Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieving duplicate records
Message
 
To
29/01/2001 12:16:52
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00469792
Message ID:
00469939
Views:
8
>How can I write a SQL statement that only retrns records where there are duplicate records in a given field. For example: Return all of the user records in states where there are more than one users.
>
>Scott Schuman
>Innovative Resource Group, Inc.
-----------------------------------------------------------------

If I undestand correctly, you wish to return records that match some criteria that return more than one record. This will return all users who live in states that have more than one user.

SELECT UserName, UserAddress, ...
FROM mytable
WHERE State IN (SELECT State, COUNT(UserID)
FROM mytable
GROUP BY State
HAVING COUNT(UserID) > 1)

Please let me know, if I missed the point completetly.
Aristotle
Previous
Reply
Map
View

Click here to load this message in the networking platform