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

Find missing entries 1

Status
Not open for further replies.

jmadd

IS-IT--Management
Mar 14, 2005
4
0
0
US
I have an employees table with employeeid
I have a timesheet table with employeeid and weekid

I would like to query weekid and find employeeid who have no entries for that week. Can't seem to get anything to work. Anybody please. What's killing me is the comparison of employees.employeeid and timesheets.employeeid.
 
Code:
SELECT Employees.employeeid,
            Timesheets.weekid
FROM Timesheets
LEFT JOIN Employees ON Employees.employeeid = Timesheets.employeeid
WHERE Employees.employeeid IS NULL
 
Something is not right. I'll play around with what you have to see if I can figure it out. It's missing the weekid I would like to search for. Thanks.
 
Hey, this is not supposed to be a mysql forum ;-)

In Standard SQL it's usually done with a NOT EXISTS:

select employeeid
from Employees
where not exists
(select *
from timesheets
where Employees.employeeid
= Timesheets.employeeid
and Timesheets.weekid = 21
)

Dieter
 
You have no idea what sanity your post has given back to me. For almost 2 days I tried every variation of not exists I could think of. Syntax was right, what's the problem? I inherited a mysql database from an RIT co-op who created an employee time sheet program for us. Wasn't aware (although it would have eventually hit me) there was difference. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top