I’m trying to update a field in 2 tables with the same value – bookings(tbl) – dropOffLocation and cars(tbl) – currentbranch.
I can get the desired result with 2 update statements such as the ones below:
UPDATE bookings b SET b.dropOffLocation = 'London' WHERE b.regNumber = 'AX03PFF'
UPDATE cars c SET c.currentBranch = 'London' WHERE c.regNumber = 'AX03PFF'
However, I’d like to combine the 2 update statements into one using a JOIN.
I’ve tried the sql below but it isn’t doing anything.
UPDATE
bookings b JOIN cars c
SET
b.dropOffLocation = 'London'
AND c.currentBranch = 'London'
WHERE b.regNumber = 'EP59YMP' AND c.regNumber = 'EP59YMP'
Can someone please help me to amend the join statement to get it working.
Thanks!
Your syntax is a little off. Use
,instead ofANDinside anUPDATE SETclause. Instead of placing both tables into theWHEREclause, I have added an equivalentONclause to theJOIN, which is a bit more readable in that it directly states the relationship between the tables.