user3361420 user3361420 - 1 year ago 103
SQL Question

SQL QUERY - Ommit ALL duplicate results

I need to return values in a column where only the unique values are returned. I know that DISTINCT will return only unique values, however i need to completely ommit any that are duplicated.


Column 1 Column 2
123456789 27/02/2014
123456789 25/02/2014
654789897 27/02/2014

To return only "654789897 27/02/2014" and ommit the other results.

Answer Source

You want to use group by and having:

select column1, column2
from table t
group by column1, column2
having count(*) = 1;

EDIT: (based on comment by knkarthick24)

Depending on what the OP intends, this might also be correct:

select column1, max(column2)
from table t
group by column1
having count(*) = 1;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download