Using Update and Left Join in SQL together not working - example

I need to use UPDATE and LEFT JOIN functions together in SQL, but it is not working. I am receiving the error notification: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN

The SQL is:
UPDATE items AS i SET item_price = '149.00' LEFT JOIN brands AS b ON i.item_brand = b.brand WHERE b.quantity > 15 ;
Could you please provide a working example of UPDATE and LEFT JOIN functions used together ?

28 Aug 2020 at 07:01 PM
0pnshow more
StorStor
Hi,

To use UPDATE and LEFT JOIN together in SQL, you have to move LEFT JOIN before SET. The code should look like:

UPDATE items AS i LEFT JOIN brands AS b ON i.item_brand = b.brand SET item_price = '149.00' WHERE b.quantity > 15 ;
31 Aug 2020 at 11:39 AM
0pnshow more
TimTim
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook & Twitter
2021 AnswerTabsTermsContact us