So i have this table A:
color ID MODEL
-----------------------------
red | 10 | HONDA
blue | 10 | TOYOTA
red | 15 |
Use NOT EXISTS
to find rows with matching id but different colors:
select *
from yourtable a
where a.color IN ('red', 'blue')
and not exists (
select 1
from yourtable b
where a.id = b.id
and b.color NOT IN ('red', 'blue')
)
Notes:
color
table