Reputation: 886
Is there a way to achieve this in MySQL (using pseudocode):
SELECT .... WHERE (1,4,3,6) IN (SELECT id FROM atable);
whereby subquery "SELECT ... atable" returns row ids 3,9,8,1
The desired effect is to do something where the 2 sets of field overlap i.e. 3 and 1 in the above example.
Reason? I have a need to compare (from PHP) a field with comma separated values and perform an action where the records are applicable. However the option of doing this in PHP is not possible in my use case for some other reason too convoluted to explain here.
I've been searching on the 'net but not stumbled on anything like it.
Upvotes: 0
Views: 139
Reputation: 7582
I think you want
SELECT id FROM atable WHERE id IN (1,4,3,6);
If the id
doesn't exist in atable
, it's not going to show up in the results. If an id
is not among the (1,4,3,6) list, it's also not going to show up. What you get then is the intersection.
Upvotes: 2