Kryptix Posted August 19, 2011 Share Posted August 19, 2011 Say I have 3 tables... employees employees_addresses employees_jobs_completed If a linking ID between employees and employees_addresses doesn't exist I want to delete all records from every table even though employees_jobs_completed may have either 0 entries or a thousand entries... Would this work? DELETE employees.*, employees_addresses.*, employees_jobs_completed FROM employees JOIN employees_addresses ON (employees.id = employees_addresses.e_id) LEFT JOIN employees_jobs_completed ON (employees.id = employees_jobs_completed.e_id) WHERE employees.id IS NULL OR employees_addresses.id IS NULL; Note the LEFT JOIN on employees_jobs_completed in case it has no entries or 1-1,000 entries. Is this the correct usage? If not, how would I go about doing it within a query? Quote Link to comment https://forums.phpfreaks.com/topic/245161-not-sure-what-to-title-this/ Share on other sites More sharing options...
fenway Posted August 21, 2011 Share Posted August 21, 2011 You're checking for either non-matching rows. Quote Link to comment https://forums.phpfreaks.com/topic/245161-not-sure-what-to-title-this/#findComment-1260272 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.