Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL help needed

Status
Not open for further replies.

santosh1

Programmer
Joined
Apr 26, 2002
Messages
201
Location
US

I wanted to get ID for employee where there was duplicate employees, because my goal is to find the duplicate
employee if it exists and delete it. I got an error message

' Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.'

So, I did the next query using EXISTS, but didn't quite get the result I was expecting.

Is there someway to run the query# 1 differently because it is what I actually
want to do. Thanks. S.


Select ID
from dbo.Data
WHERE CITY in (select city, firstname, lastname from dbo.Data
group by city, firstname, lastname having count(*) > 1)
order by city

Select ID,FirstName,LastName,City
from dbo.Data
WHERE exists (select city, firstname, lastname from dbo.Data
group by city, firstname, lastname having count(*) > 1)
order by city
 
Access has a find duplicates query wizard...try that out first.
 
I did a query like this using oracle, I am not exactly sure if it will work in access, but you can give it a try.

select * from dbo.Data where (city, firstname, lastname) in (city, firstname, lastname
from dbo.Data
group by city, firstname, lastname
having count(*) > 1)
order by city, firstname, lastname;


Dodge20
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top