Jump to content

mysql query on negative join result


jwoker

Recommended Posts

Novice here wondering how to get a select query to return a set where there are no records in the joined table.SELECT * FROM job JOIN orders ON job.id = orders.job_id WHERE orders.job_id .....I want to select all from job where there are no corresponding records in orders?Is that possible?Thanks

Link to comment
Share on other sites

If you used a left join then it would select every record from the job table, and only the matching records from the other table. Records from the job table without a matching record in the other table would have null values in the joined columns.If you want to select only records from the job table that don't have orders, you could do this:SELECT * FROM job WHERE id NOT IN (SELECT job_id FROM orders)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...