Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Repeatd Fields

Author  Topic 

sambrown18
Starting Member

14 Posts

Posted - 2008-04-22 : 06:13:38
I wont to search my table for repeated fields i wont to know what surnames are repeated.

I think i need to use the count comand but not sure how i should integrate it

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-22 : 06:14:47
SELECT surname from YourTable GROUP BY surname HAVING COUNT(*) > 1
Go to Top of Page

sambrown18
Starting Member

14 Posts

Posted - 2008-04-22 : 06:22:12
thanks that does work how do i put the second column in as well i need to see what surnames have what sessions
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-22 : 06:44:33
SELECT surname,session,other fields... FROM YourTable WHERE surname in (SELECT surname from YourTable GROUP BY surname HAVING COUNT(*) > 1)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-22 : 09:11:52

or

SELECT t1.* FROM YourTable t1 inner join
(SELECT keycol,surname from YourTable GROUP BY surname HAVING COUNT(*) > 1) as t2
on t1.keycol=t2.keycol

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -