Skip to content
Advertisement

How do i perform a conditional update in SQL with data from multiple tables?

Trying to run an update on a column and i’m getting a syntax error on the FROM line connecting the tables

UPDATE inv_loc
SET inv_loc.product_group_id = 'TEMP'
WHERE inv_mast_ud.eh_spk LIKE '%T'

FROM
inv_mast_ud
left join inv_loc on inv_mast_ud.inv_mast_uid = inv_loc.inv_mast_uid

Advertisement

Answer

The WHERE clause belongs at the end of the update join statement:

UPDATE il
SET il.product_group_id = 'TEMP'
FROM inv_loc il
INNER JOIN inv_mast_ud imu
    ON imu.inv_mast_uid = il.inv_mast_uid
WHERE
    imu.eh_spk LIKE '%T';

See SQL update query using joins for a good canonical answer to your question.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement