Having difficulty writing a statement that will allow me to:
UPDATE column C in DB1.table1 with data from column B in DB2.table2 IF column B IS NOT null AND column A FROM DB1.table1 = column A FROM DB2.table2 (matching IDs)
Can’t tell if I need to use a CASE statement or IF. Appreciate any help, thanks.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
UPDATE DB1.table1
JOIN DB2.table2 ON DB2.table2.B IS NOT NULL -- IF column B IS NOT null
AND DB1.table1.A = DB2.table2.A -- AND column A FROM DB1.table1
-- = column A FROM DB2.table2 (matching IDs)
SET DB1.table1.C = DB2.table2.B -- UPDATE column C in DB1.table1
-- with data from column B in DB2.table2
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0