Jin Yong
Jin Yong

Reputation: 43778

How to display no duplicate records in SQL Server

Does anyone know how can I display records that are not duplicated record inside results in SQL Server?

Upvotes: 1

Views: 14663

Answers (3)

Martin Smith
Martin Smith

Reputation: 453287

Another interpretation of the question.

SELECT *
FROM   yourtable t1
WHERE  NOT EXISTS
       (SELECT *
       FROM    yourtable t2
       WHERE   t1.col_to_match_for_duplicates=t2.col_to_match_for_duplicates
       AND     t1.primarykey                <> t2.primarykey
       )

Upvotes: 2

Charles Bretana
Charles Bretana

Reputation: 146499

If you really meant "records that with no duplicate record ", i.e., every row that exists once, and only once, Try this:

  Select * From Table
  Group By [Here list all columns in Table]
  Having Count(*) = 1

Upvotes: 2

Byron Whitlock
Byron Whitlock

Reputation: 53861

Use distinct

SELECT DISTINCT * FROM table

Or use group by

select field1,field2,field3 FROM table GROUP BY field1, field2, field3

Upvotes: 3

Related Questions