MySQL: Selecting non-unique records
Scenario: you want to select all records that have a non-unique value in a column. Use a subquery:
SELECT ... FROM ... WHERE ... IN ( SELECT ... FROM ... GROUP BY ... HAVING COUNT(*) > 1 );
So, to give an example, you want to select all rows from the table "books" that have a non-unique title:
SELECT * FROM books WHERE title IN ( SELECT title FROM books GROUP BY title HAVING COUNT(*) > 1 );
0 TrackBacks
Listed below are links to blogs that reference this entry: MySQL: Selecting non-unique records.
TrackBack URL for this entry: http://www.robbiebow.co.uk/mt/mt-tb.cgi/68

Leave a comment