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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Subquery To Return Unique Rows..

Status
Not open for further replies.

mmignot

Programmer
Jul 16, 2001
44
US
Hello,

I am trying to return from a query, a list of employees that
entered more than one timecard within the same reporting
period. Here is the query I'm trying to develop:

---------------------------------------------
SELECT a.LastName AS LastName,
a.FirstName AS FirstName
FROM Employee AS a
WHERE a.Active<>0
AND a.Employee_ID In
(SELECT b.Employee_ID
FROM Time_Card AS b
WHERE b.PeriodFrom = '02/04/2002'
AND b.PeriodTo = '02/10/2002')
ORDER BY a.LastName, a.FirstName;
---------------------------------------------
This is returning all of the employees. Can someone tell me what I need to do in order to just return the employees that
have more than one time in the same reporting period??

Thanks,
MM :)
 
You need to include an aggregate function to determine which employee have multiple cards.
[tt]
SELECT
a.LastName,
a.FirstName
FROM Employee AS a
WHERE a.Active<>0
AND b.PeriodFrom = '02/04/2002'
AND b.PeriodTo = '02/10/2002'
GROUP BY a.LastName, a.FirstName
HAVING Count(*)>1

ORDER BY a.LastName, a.FirstName[/tt] Terry L. Broadbent - Salt Lake City, UT
Home of the 2002 Winter Olympics (Feb 8-24)
 
Your suggestion worked Terry!!

Thanks so much!!
MM :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top