Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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, FirstNameFROM EMPLOYEESORDER BY UserIDHAVING 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, FirstNameFROM EMPLOYEES where UserId in (select UserId from Employees group by UserId having COUNT(*) > 1)ORDER BY UserID