473,473 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

Jan 19 '06 #1
3 1056
MC
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

<gw*****@kc.rr.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.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

Jan 19 '06 #2
It worked perfect! Thanks for your help!!

Jan 20 '06 #3
Don't forget to add a constraint to the table so this will not happen
again.

Jan 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: news | last post by:
Hi there, I have a table in an Oracle 9i R2 database containing the following string" "It's so easy" When I try to execute the following query: SELECT EXPRESSION FROM EXPRESSIONS WHERE...
2
by: m3ckon | last post by:
Hi there, had to rush some sql and am now going back to it due to a slow db performance. I have a db for sales leads and have created 3 views based on the data I need to produce. However one...
3
by: Bill | last post by:
I'm trying to do something which seems like it should be really easy, but I can't seem to figure it out. Basically I have an unbound form with the usual combo boxes, option groups text boxes, etc....
1
by: u473 | last post by:
I am scratching my head with the required quotes and parentheses. I started with an existing working Query with Running Total by date. Now I need to produce a running total by quarter day, so I...
11
by: kirpi | last post by:
There is an SQLServer database somewhere, and I would like to grab and publish some data to my web pages. I was told: "please, do", and given server address, database name, id, and password. My...
6
by: No Spam Man | last post by:
Hi, I am not a programmer and in the past have only created very simple, flat file databases. Although I'm a newbie, I think I could probably figure out basic Boolean logic and financial...
10
by: sara | last post by:
I have been volunteered to write a simple system to help a non-profit enter and track information on the elders they serve. (It's actually a fascinating activity, and very rewarding to be helping...
7
by: Brave | last post by:
I am hoping for a code example of how to do this, and hopefully it will help me to see an easy way to code what seems to be a huge monster. I need to create a form that has two pulldown menues...
1
by: basestring | last post by:
Hi, I need help for my program. I'm new With PHP but i have programming skills in VB so it's quit easy to understand this language, however. i got my self in some problems that i don't understand....
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.