lundi 26 février 2018

How to reference another table value when updating current table in an IF statement

Basically, I would like to update a column in table1 by writing an if statement that references a column in table1 and another column in table2. My idea for the code goes something like this, but I get an error in my syntax when referencing table2 in the IF statement.

UPDATE table1 JOIN table2 ON table1.col_a = table2.col_b
SET 
    table1.POD = IF(table1.col_x LIKE '2%' AND table2.col_y = 'YES', 1, NULL)

I'm confused as when for example I update my table1/join with table2:

SET table1.random_col = table1.random_col1 * table2.random_col2

something like the above works fine with no problems.

Aucun commentaire:

Enregistrer un commentaire