Ladas125 Ladas125 - 4 months ago 5
SQL Question

Select IDs where every column of same ID meets condition

I want to select IDs where every column of same ID meets condition but I can't figure out the query to get that result.
The table looks like this:

text | id
----------
text1 | 1
text2 | 1
text3 | 1
text1 | 2
text3 | 2
text2 | 3


Excepted result
SELECT id FROM table WHERE text IN ("text1", "text2")


id
--
1

Answer
SELECT id
FROM `table` AS t1
INNER JOIN `table` AS t2 USING (id)
WHERE t1.text = "text1" AND t2.text = "text2"
Comments