Monday, January 19, 2015

How to select only duplicate records?

This is a guideline to select:

First ways:
 
Select State FROM Area
GROUP BY State
Having COUNT(*) > 1
 
Second ways:
 
 
SELECT DISTINCT a1.State
FROM AREA a1
JOIN AREA a2
  ON a1.AreaId != a2.AreaId  -- assume there is a Key to join on
  AND a1.State = a2.State    -- and such that different Areas with same State