Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

This query must be easy but need help
I have a table like this:

Name, SSN
Joe Smith, 1111
Tom Why, 2222
Larry Sam, 3333
Paul Tom, 4444
Steve bob, 1111

I want a query to pull off

Joe Smith, 1111
Steve bob, 1111

because someone accidently put in two different names with the same
SSN. There should only be one 1111 in the SSN field in the whole
database. I want to pull the duplicate SSN with the name. How can one
query do this. I can write a VB program to do it but I think a query
should work.

I know how to do this:

SELECT     SSN, COUNT(*) AS cnt
FROM         test
GROUP BY fSSN
HAVING      (COUNT(*) > 1)

to find the duplicate SSN but I need the name listed with the SSN also.
Any help?? Thanks!!

Sheila


Report this thread to moderator Post Follow-up to this message
Old Post
gwhite1@kc.rr.com
01-19-06 08:24 AM


Re: This query must be easy but need help
try this one:

select test.Name, test.SSN
from
test
inner join (select SSN from test group by SSN having count(*)>1) t2 on
test.ssn = t2.ssn

<gwhite1@kc.rr.com> wrote in message
news:1137647549.440302.217140@g49g2000cwa.googlegroups.com...
>I have a table like this:
>
> Name, SSN
> Joe Smith, 1111
> Tom Why, 2222
> Larry Sam, 3333
> Paul Tom, 4444
> Steve bob, 1111
>
> I want a query to pull off
>
> Joe Smith, 1111
> Steve bob, 1111
>
> because someone accidently put in two different names with the same
> SSN. There should only be one 1111 in the SSN field in the whole
> database. I want to pull the duplicate SSN with the name. How can one
> query do this. I can write a VB program to do it but I think a query
> should work.
>
> I know how to do this:
>
> SELECT     SSN, COUNT(*) AS cnt
> FROM         test
> GROUP BY fSSN
> HAVING      (COUNT(*) > 1)
>
> to find the duplicate SSN but I need the name listed with the SSN also.
> Any help?? Thanks!!
>
> Sheila
>



Report this thread to moderator Post Follow-up to this message
Old Post
MC
01-19-06 08:24 AM


Re: This query must be easy but need help
It worked perfect! Thanks for your help!!


Report this thread to moderator Post Follow-up to this message
Old Post
gwhite1@kc.rr.com
01-20-06 01:24 AM


Re: This query must be easy but need help
Don't forget to add a constraint to the table so this will not happen
again.


Report this thread to moderator Post Follow-up to this message
Old Post
--CELKO--
01-22-06 08:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 04:12 AM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006