Saturday, 24 August 2013

Mysql update column based on a string from another table

Mysql update column based on a string from another table

I need to update a column called PrebookCB in a table called Workorders
and set it to 1 if the CustomerStatus column in Table Customers equals the
string 'Good - Prebook'. I have tried various joins ect and cant seem to
get it to work. This seems to be the closest. there would be multiple
Workorders for each customer. Workorders have a column called CustomerID
that matches the Customers primary index column called CustomerID
UPDATE Workorders
JOIN Customers
ON Workorders.CustomerID = Customers.CustomerID
SET Workorders.PrebookCB = 1
WHERE Customers.CustomerStatus = 'Good - Prebook'

No comments:

Post a Comment