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

Selecting records that do not appear in both tables 1

Status
Not open for further replies.

drewson

MIS
Jun 3, 2003
50
US
I have two tables:

labusers
fields: userid (key), email, firstname, lastname... etc

labresults
fields: userid (key), surveyid (key)... etc survey info

I need to select email from labusers when their userid does not exist in labresults for a specified surveyid. (Basically, list the emails for all who have not taken a given survey)

Any suggestions?
 
Code:
SELECT
   u.email
FROM
      labusers u
   left join
      labresults r
   on
      u.userid = r.userid
 and r.surveyid = <your value>
WHERE
   r.userid is null
 
Thanks swampBoogie... I knew I'd be using left join, but couldn't figure out where the surveyid would be set... I was trying to set it in the where section, like sleipnir214's post, but that made all the surveyid fields null.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top