• Increase font size
  • Default font size
  • Decrease font size
Home T-SQL Find duplicate rows

Find duplicate rows

E-mail Print
(0 votes)

play_up_128 Each row in a table is characterized by a primary key. Now it is noticed that in your system the key occurs twice. This should not really. With this simple query you can quickly find duplicate rows in your table!

The following query shows how two people can find, based on EMPLOYEE NUMBER. This would be the primary key from the source.

  SELECT DISTINCT
 EMPLOYEE NUMBER
    EMPLOYEES FROM EMPLOYEES
 EMPLOYEENUMBER GROUP BY EMPLOYEE NUMBER
 COUNT ( EMPLOYEENUMBER ) > 1 HAVING COUNT (EMPLOYEE NUMBER)> 1 

Then do you take these two numbers are not loading your data. QUERY below you can filter employees double.

   * SELECT *
 ( FROM (
 EmployeeNumber, SELECT Employee Number,
 OVER ( PARTITION BY EMPLOYEENUMBER ORDER BY EMPLOYEENUMBER ASC ) AS Rij Row_number () OVER (PARTITION BY EMPLOYEE NUMBER EMPLOYEE NUMBER ORDER BY ASC) AS Row
   EMPLOYEES AS LM FROM EMPLOYEES AS LM
 AS X ) AS X
   X. Rij <= 1 WHERE X. Row <= 1 

What we do is add a row number for each unique Employee Number. If a number appears twice gets the row number 2. Then we retrieve all rows with the number> one way!

Copyright 2008. All Rights Reserved.

Trackback (0)

TrackBack URI for this post

Comment (0)

RSS feed Comments

Write comment

bold italicize underline strike url image quote smile wink laugh grin angry sad shocked cool tongue kiss cry
| groter smaller | bigger
security image
Write the displayed characters

busy
 

Ninja RSS Syndicator