domminn domminn - 1 year ago 89
SQL Question

SQL Select multiple values in one column, with different conditions

I've products-filter relation table.

For example: I want to select all products with color red and yellow which have medium size

WHERE (filter_id = 208 OR filter_id = 211) AND filter_id = 210

I'cant figure out how to use AND condition on same column

enter image description here

Answer Source

Looks like you want to group your data by product_id and the take only those having the conditions you mentioned

select product_id
from your_table
group by product_id
having sum(filter_id = 210) > 0
   and sum(filter_id = 208 OR filter_id = 211) > 0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download