Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query
Message
From
11/04/2001 07:54:31
 
 
To
11/04/2001 02:08:18
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Re: Query
Miscellaneous
Thread ID:
00494301
Message ID:
00494355
Views:
18
This is a really basic query which makes use of the GROUP BY and HAVING clauses:

SELECT lastname, COUNT(*)
FROM persontable
GROUP BY lastname
HAVING COUNT(*) > 1

This query will return all the last names that are duplicated and the number of times their duplicated. If you want to return the entire name, you'll need to use the above query as a subquery:

SELECT firstname, lastname
FROM persontable
WHERE lastname IN (
SELECT lastname, COUNT(*)
FROM persontable
GROUP BY lastname
HAVING COUNT(*) > 1)

-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform