03-07-2021, 04:11 AM
(03-06-2021, 12:32 PM)iRedds Wrote: Be careful. The proposed option can play a cruel joke with you.Thanks, actually in my case it is only "d" that has different values, "id" is the same inside each loop, e.g. for all 4 queries.
This request can be written as
Code:SELECT *
FROM table
WHERE
(id = 1 AND (d = 20 OR d = 21 OR d = 22 OR d = 25))
OR (id = 2 AND (d = 20 OR d = 21 OR d = 22 OR d = 25))
OR (id = 3 AND (d = 20 OR d = 21 OR d = 22 OR d = 25))
OR (id = 4 AND (d = 20 OR d = 21 OR d = 22 OR d = 25))
OR (id = 5 AND (d = 20 OR d = 21 OR d = 22 OR d = 25))
Depending on the logic of your database, this may conflict with the conditions.
https://www.db-fiddle.com/f/ckHvgzVN2u8a1dtv7GoNMZ/0
Perhaps you'd better use UNION