Blogs

How to find duplicate rows in SQL Server

Richard Lewis

I ran into this problem the other day at work with duplicate rows while trying to merge data from two separate tables into the same table. I couldn’t remember so I just ran a quick search using Google and came across the solution on a Microsoft knowledge base page.

-------------------------------------------------------
**_The first step is to identify which rows have duplicate primary key
values:_**
SELECT col1, col2, count(*)FROM t1GROUP BY col1, col2HAVING count(*) > 1
**_This will return one row for each set of duplicate PK values
in the table. The last column in this result is the number of
duplicates for the particular PK value._**

col1               col2

Happy Birthday Gogorichie.com

Richard Lewis

On July 9th 2002 Gogorichie.com was born. Here are some stats recorded during the last year.

3,318 unique visitors came to the site, as determined by typical behavior of browsers with a non-rotating IP address and including a projection of the true number of visitors with rotating IP addresses.

The web site received 5,693 visits. A typical visitor examined 17.19 distinct files before leaving the site. A typical visit lasted for 6.49 minutes. The longest visit lasted for 938 minutes.