Select DISTINCT on specific column? - TechRepublic
General discussion
July 10, 2001 at 04:23 AM
andrew

Select DISTINCT on specific column?

by andrew . Updated 24 years, 11 months ago

I’d like to query a table, returning only rows where a specific column has unique values. Something like:

SELECT DISTINCT Col1, Col2, Col3
FROM Table1

but only have the ‘DISTINCT’ predicate apply to Col1, not the entire row.

I’m able to count the unique rows using a HAVING COUNT(*)>1 clause, but I can’t seem to find a concise way (other than temp tables) to filter them out.

I’m using SQL Server 7.0.

TIA for any pointers.

This discussion is locked

All Comments