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
 Multiple Values, One Table, One Column

Author  Topic 

meberg66219
Yak Posting Veteran

65 Posts

Posted - 2013-09-30 : 12:19:30
I have a table that uses a column named UserID and there are ocassions where an user is terminated from employment and then comes back to the company again and the system generates the same UserId at that time. What I need is a query that will give me all users who have the same UserID. I have a unique ID in the same table. I tried the below but I get an error on the query.

SELECT ID, UserID, TermDate, LastName, FirstName
FROM EMPLOYEES
ORDER BY UserID
HAVING COUNT(*)>1

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-09-30 : 12:38:09
This, or a variation of this is probably what you need:
SELECT ID, UserID, TermDate, LastName, FirstName
FROM EMPLOYEES
where UserId in (select UserId from Employees group by UserId having COUNT(*) > 1)
ORDER BY UserID
Go to Top of Page

meberg66219
Yak Posting Veteran

65 Posts

Posted - 2013-09-30 : 14:12:04
Thank you that worked perfectly!
Go to Top of Page
   

- Advertisement -