Mariusz Z. Mariusz Z. - 1 year ago 92
MySQL Question

UPDATE SET information from 3 tables

table_a (item_id, item_desc)

table_b (item_id, item_name)

table_c (item_name, item_desc)

I need to

set table_a.item_desc=table_c.item_desc

No matter what am I doing I'm still getting errors.

This is my final work:

UPDATE table_a
SET table_a.item_desc = table_c.item_desc
FROM table_a
INNER JOIN table_b
ON table_a.item_id = table_b.item_id
INNER JOIN table_c
ON table_b.item_name = table_c.item_name;

Answer Source

You have syntax error. In MySQL you don't need to add FROM clause when using UPDATE with JOIN.
Also add table alias for better readability.

UPDATE table_a A
INNER JOIN table_b B ON A.item_id = B.item_id
INNER JOIN table_c C ON B.item_name = C.item_name
SET A.item_desc = C.item_desc ;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download