grippat Posted September 26, 2007 Share Posted September 26, 2007 I have two tables (Companies and Company_machines) and each row in Companies may have several or no related rows in Company_machines. I'm trying to update all the rows in Companies that don't have any related rows in Company_machines. Every row in Company_machines has a Company_ID field that contains the ID of the Company it belongs to in the Companies table. How would I write a MySQL statement that updates just one field in Companies that don't have any Company_machines related to them? Here's what I tried but wasn't successful: UPDATE Companies coLEFT JOIN Company_machines cm ON cm.company_id = co.idSET co.prospect = "yes" Link to comment Share on other sites More sharing options...
justsomeguy Posted September 26, 2007 Share Posted September 26, 2007 UPDATE Companies SET prospect='yes' WHERE id NOT IN (SELECT company_id FROM Company_machines) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.