0

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.

1
  • That syntax is a "row constructor", which is not what you need. Commented Jun 17, 2021 at 18:36

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.