I am running following query.
SELECT T1.C1, T2.C2...,
IF( T1.C1<>T2.C1,"Changed","1") AS NewColumn
From T1 INNER JOIN T2
Where condition..
I am getting syntax error for IF statement.
Motive is to compare columns from two different tables, if not equal save as "Changed" in NewColumn of third table.. This is a Insert INTO query.
T-> Table
C->Column
You have to use CASE WHEN in this context.
SELECT T1.C1,
T2.C2...,
CASE WHEN T1.C1<>T2.C1 THEN 'Changed' ELSE '1' END AS NewColumn
FROM T1
INNER JOIN T2
WHERE condition
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With