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

help with a query 2

Status
Not open for further replies.

netooi25

Programmer
Jul 30, 2004
25
US
i have a table called tblPeople in my database that keeps track of people.
I use a autonumber field for a primary key..

I have a 2nd table called tblattendance with 2 fields.
I was using PersonID(autonumber from tblPeople), Date as primary key in this table.

I dont know if this is possible right now the way i have the tables designed.

I can easily create a query to find out what people were present on a certain date, but the opposite is giving me trouble. The query i want to do is selecting all the people in tblPeople that were not present on a particular date. Any help will be appreciated.

Thanks,
Netooi
 
there are two ways to do it:
Code:
select P.PersonID
  from tblPeople as P
left outer
  join tblattendance as A
    on (
       P.PersonID
     = A.PersonID
   and A.[D4te] = '2004-08-31'
       )
 where A.PersonID is null
or
Code:
select P.PersonID
  from tblPeople as P
 where not exists
       ( select 1 
           from tblattendance
          where PersonID
              = P.PersonID
            and [D4te] = '2004-08-31'
       )
note i use [D4te] because Date is a reserved word

rudy
SQL Consulting
 
take the query that gives you the results you want, modify it so it only gets the personID and use it in a subquery (your query is red):
Code:
SELECT blah, blah from table WHERE PersonID NOT IN([COLOR=red]SELECT PersonID from Somewhere WHERE whatever = 'This'[/color])

Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top