Jump to content

Updating only records in table with no related record?


Recommended Posts

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...