Saturday, 14 January 2017

SQL - Double Rows

Hi All, here a fast script to find double rows!
Happens to have some table/s with 2 or more rows which have the same value on field, to find this rows here there's a script which select all double rows in table, 
After you can choose to delete or analize why there are double.

--lwebcode Select all double rows in a table
SELECT     City, Address, Zip, Year,  COUNT(*) AS Expr1
FROM        MyTable
GROUP BY  City, Address, Zip, Year
HAVING      (COUNT(*) > 1)


--lwebcode For a single  column double rows:
SELECT     City  COUNT(*) AS Expr1
FROM        MyTable
GROUP BY  City

HAVING      (COUNT(*) > 1)

No comments:

Post a Comment