SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Multiple Values, One Table, One Column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

meberg66219
Yak Posting Veteran

USA
65 Posts

Posted - 09/30/2013 :  12:19:30  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3562 Posts

Posted - 09/30/2013 :  12:38:09  Show Profile  Reply with Quote
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

USA
65 Posts

Posted - 09/30/2013 :  14:12:04  Show Profile  Reply with Quote
Thank you that worked perfectly!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000