sql - AND query a m-to-n table -
i have simple m-to-n table in database , need perform , search. table looks follows:
column | column b 1 x 1 y 1 z 2 x 2 c 3 3 b 3 c 3 y 3 z 4 d 4 e 4 f 5 f 5 x 5 y
i want able 'give me column has x , y in column b (returning 1 , 5 here), can't figure out how form query.
i tried select column_a table column_b = x , columb_b = y
seems return if column somehow both. fundamentally possible, or should have different table layout?
here's 1 way:
select table1 b in ('x', 'y') group having count(distinct(b)) = 2
if guaranteed (a,b) unique, can rid of distinct well.