SQL | Brain Goo https://www.popmartian.com/tipsntricks Carpe Crap 'em Fri, 06 Feb 2009 17:00:59 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.10 SQL: Select duplicate rows, select indistinct rows https://www.popmartian.com/tipsntricks/2008/10/27/sql-select-duplicate-rows-select-indistinct-rows/ https://www.popmartian.com/tipsntricks/2008/10/27/sql-select-duplicate-rows-select-indistinct-rows/#comments Mon, 27 Oct 2008 16:09:29 +0000 http://www.popmartian.com/tipsntricks/?p=67 Using SQL, MySQL or whatever your favorite database may be, we all know using SELECT DISTINCT will return unique values in case a value appears more than once in a table. How do you fine duplicates? What if I want … Continue reading →

The post SQL: Select duplicate rows, select indistinct rows first appeared on Brain Goo.

]]>
Using SQL, MySQL or whatever your favorite database may be, we all know using SELECT DISTINCT will return unique values in case a value appears more than once in a table.

How do you fine duplicates? What if I want to know where the duplicates are?

The trick is to use count() and compare it to an integer.

SELECT count(*), locations.* FROM locations GROUP BY number HAVING COUNT(*) > 1

That will select a count of unique instances of a value from a table called “locations”, group them by a field called “number” where the count is greater than 1. In other words, it will return all the fields where there are more than one instance of the same value in the column “number”.

Did you find this post useful or have questions or comments? Please let me know!

The post SQL: Select duplicate rows, select indistinct rows first appeared on Brain Goo.

]]>
https://www.popmartian.com/tipsntricks/2008/10/27/sql-select-duplicate-rows-select-indistinct-rows/feed/ 1