I've written this code to find duplicates and it works fine:
SELECT *
FROM StyleTable
GROUP BY Color
HAVING count(*) > 1
The problem is, it's returning just one of the duplicate rows. Is it possible to return all the duplicate rows? I'm guessing it may have something to do with the 'GROUP BY' but I'm not sure how to change it. I don't want to delete the values, just return them.
If you do not include DISTINCT in a SELECT clause, you might find duplicate rows in your result, because SQL returns the JOB column's value for each row that satisfies the search condition. Null values are treated as duplicate rows for DISTINCT.
Select Distinct will remove duplicates if the rows are actually duplicated for all columns, but will not eliminate 'duplicates' that have a different value in any column. Thanks.
You have to join back to the table again to get the duplicates I think. Something like:
SELECT *
FROM StyleTable
WHERE Color IN (
SELECT Color
FROM StyleTable
GROUP BY Color
HAVING count(*) > 1
)
SELECT s.*
FROM StyleTable s
INNER JOIN (SELECT Color
FROM StyleTable
GROUP BY Color
HAVING COUNT(*) > 1) q
ON s.Color = q.Color
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With