Answer the question
In order to leave comments, you need to log in
How to select dialog ID and interlocutor ID from the same table?
Hello!
I have a table which contains fields:
SELECT dialog_id
FROM members
WHERE user_id = 1 OR user_id = 2
GROUP BY dialog_id HAVING count(dialog_id) = 2
Answer the question
In order to leave comments, you need to log in
This option pops into my head:
SELECT dialog_id FROM members
GROUP BY dialog_id HAVING count(user_id) = 2
AND dialog_id IN (
SELECT dialog_id
FROM members
WHERE user_id = 1 OR user_id = 2
GROUP BY dialog_id HAVING count(user_id) = 2)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question