[go: up one dir, main page]

0% found this document useful (0 votes)
29 views1 page

Remove Duplicates

This statement uses the GROUP BY clause to find duplicate rows in columns of a table by grouping rows, counting occurrences of each group, and keeping groups with a count greater than one.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Remove Duplicates

This statement uses the GROUP BY clause to find duplicate rows in columns of a table by grouping rows, counting occurrences of each group, and keeping groups with a count greater than one.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Using GROUP BY clause to find duplicates in a table

This statement uses the GROUP BY clause to find the duplicate rows in both a and b
columns of the t1 table:

SELECT
a,
b,
COUNT(*) occurrences
FROM t1
GROUP BY
a,
b
HAVING
COUNT(*) > 1;
Code language: SQL (Structured Query Language) (sql)
Here is the result:

SQL Server Find Duplicates using GROUP BY clause


How it works:

First, the GROUP BY clause groups the rows into groups by values in both a and b
columns.
Second, the COUNT() function returns the number of occurrences of each group (a,b).
Third, the HAVING clause keeps only duplicate groups, which are groups that have
more than one occurrence.

You might also like