count query

Payal Patel

Registered User.
Local time
Yesterday, 18:24
Joined
Nov 3, 2009
Messages
34
Hi,
I have a table with employee ID#'s in it. I am trying to run a query that:
if the same emp ID is listed more than 3 times, i want it to return the information for that employee. Is there a way to do this?
Thanks in advance,
P.
 
Hi,

You can use a subquery to return a list of emloyee ids that occur 3 or more times and then use this in the where clause of your main query.

Code:
SELECT * FROM YourTable
WHERE
EmployeeId IN 
(
   SELECT EmployeeId 
   FROM YourTable 
   GROUP BY EmployeeId 
   HAVING COUNT(EmployeeId) >= 3 
)
 

Users who are viewing this thread

Back
Top Bottom