Skip to content
Advertisement

SQL conditions – select ID who have multiple values in a column

Having this COLORS table:

enter image description here

How do I select the ID who have both COLOR RED & PINK? (Could be more than 2 colors)

Advertisement

Answer

A simple method is aggregation and having:

This assumes that your original data has no duplicates. If that is the case, use count(distinct color) = 2.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement