Let's say there is this table colors
| id | source |
|---|---|
| 1 | red |
| 1 | green |
| 1 | orange |
| 2 | red |
| 2 | red |
| 3 | black |
| 3 | green |
| 4 | red |
| 5 | green |
What I want is the list of all id that have as only source the value 'red', so 2 and 4.
To be clear
select distinct id from colors where source = 'red'
would give 1,2 and 4, where 1 has 'green' and 'orange' in addition to 'red', so no.
Here the SQL to create the table
create temp table colors as
select *
from (values (1, 'red'),(1, 'green'),(1, 'orange'),(2,'red'),(2, 'red'),(3, 'black'),(3,'green'),(4,'red'),(5,'green'))
as t (id,source)
How to query this?