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..... Link to comment https://forums.phpfreaks.com/topic/122255-solved-pulling-records-from-one-table-not-featured-in-another-table/ 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 Link to comment https://forums.phpfreaks.com/topic/122255-solved-pulling-records-from-one-table-not-featured-in-another-table/#findComment-631273 Share on other sites More sharing options...
Buchead Posted September 1, 2008 Author Share Posted September 1, 2008 Cool. Thanks for that. Link to comment https://forums.phpfreaks.com/topic/122255-solved-pulling-records-from-one-table-not-featured-in-another-table/#findComment-631284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.