DEV Community

Discussion on: How to write this SQL select the best way?

Collapse
 
dmfay profile image
Dian Fay • Edited
select bom_id
from line
where item_id = 'KetchupBottle' or item_id = 'RubberDuckey'
group by bom_id
having count(*) = 2;

The having clause needs to check that the count equals the number of item ids you're matching.

Collapse
 
darksmile92 profile image
Robin Kretzschmar

Hey Dian thanks for that suggestion! The having was what I've been missing, worked out very well, thanks a lot! 😊

It's those kinda tasks where I can learn a lot from.