'How to filter out all records that have duplicates in SQL?

Trying to get this result from a table with duplicates

red
red
red
blue
green

to

blue
green

Totally omitting all the records that has duplicates and only bringing in the unique records

sql


Solution 1:[1]

Use GROUP BY and HAVING clause...

    select color
    from table1
    group by color
    having count(color) = 1

Solution 2:[2]

If you need more than just the colours.

select *
from paintmess
where colour in (
   select colour 
   from paintmess 
   group by colour 
   having count(*)=1
   );
id colour
4 blue
5 green

db<>fiddle here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Isolated
Solution 2 LukStorms