Buchead Posted September 1, 2008 Share Posted September 1, 2008 Hello... I should know the answer to this but can't seem to work it out. Have 2 tables: staff: staffID - unique ID staffName - name depts: deptID - unique ID deptName - name staffID - linked to staffID in `staff` I want to pull out a list of all names from `staff` who are not listed in `depts`. Can pull out the list of staff in depts but not the other way round. Any pointers most appreciated..... Quote Link to comment Share on other sites More sharing options...
fenway Posted September 1, 2008 Share Posted September 1, 2008 You want a left join to include non-matching rows, and then filter only those that don't match (i.e. null-ed out): select s.* from staff as s left join depts as d using ( staffID ) where d.staffID IS NULL Quote Link to comment Share on other sites More sharing options...
Buchead Posted September 1, 2008 Author Share Posted September 1, 2008 Cool. Thanks for that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.