Find duplicate rows in a database using standard SQL
Thanks goes to Xgc in #mysql on freenode for showing me this little one-liner. We needed to add a unique key to one of our tables, and a duplicate was in our midst. Enter this handy one-liner:
SELECT field1, count(*) FROM tbl1 GROUP BY field1 HAVING count(*)>1;
problem solved, a nice simple list of the duplicated rows in front of you.
Comments
Pingback from Something is going on » Find duplicate rows in a database using standard SQL
Date: January 31, 2006, 1:22 am
[…] Via kinabalu: SELECT field1, count(*) FROM tbl1 GROUP BY field1 HAVING count(*)>1; […]
About mystic
Mystic is located in Southern California,
we are a dedicated team of magic makers for your
organizations needs. We can take your needs and
turn them into the solution that fits perfectly
for your company.
Learn More
Categories
- Apple (3)
- Java (9)
- Technology (3)
Archive
- March 2007 (2)
- September 2006 (1)
- August 2006 (2)
- April 2006 (1)
- March 2006 (1)
- February 2006 (1)
- January 2006 (3)
Write a comment