Thursday, December 5, 2019

Remove Duplicate Rows HAVING ( COUNT(*) > 1 )

Finding duplicates in a table.  Find all email addresses that exist more than one time:
SELECT customer,
 COUNT(customer) AS NumOccurrences
FROM SalesTable
GROUP BY customer
HAVING ( COUNT(customer) > 1 )


Find rows that occur exactly once:
SELECT customer
FROM SalesTable
GROUP BY customer
HAVING ( COUNT(customer) = 1 )

No comments:

Post a Comment