Skip to content

Instantly share code, notes, and snippets.

@oak-tree
Created September 3, 2014 14:52
Show Gist options
  • Select an option

  • Save oak-tree/9f710374d33fbb2caf03 to your computer and use it in GitHub Desktop.

Select an option

Save oak-tree/9f710374d33fbb2caf03 to your computer and use it in GitHub Desktop.
select all records that doesn't have relation to another table
SELECT rp.report_id, rp.project_id, rp.project FROM `reports_projects` as rp where rp.project not in (select p.CODE from projects as p) limit 50
@oak-tree
Copy link
Author

oak-tree commented Sep 3, 2014

another options
select rp.report_id,rp.project from reports_projects as rp LEFT JOIN projects as p ON (rp.project = p.code)
where p.code is NULL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment