I got a numeric value in Foo.A and it has its equivalent in Bar but with a string prefix ("Z"). I'm trying to append the "Z" to the Bar.A col value. I also tried with CONCAT but without any success. This following codes returns "Unknown column Z".
UPDATE Foo, Bar
SET Foo.B = Bar.B
WHERE Foo.A = Z + Bar.A
For example 14 (Foo.A) = Z14 (Bar.A).
If your syntax works, then it is likely you are using MySQL. In any case, the problem is that you need quotes around string constants. So try this:
UPDATE Foo join
       Bar
       on Foo.A = concat('Z', Bar.A)
    SET Foo.B = Bar.B;
You should always use single quotes for string and date constants, regardless of the database. That is the ANSI standard and it reduced the possibility of error.
You are missing the single quotes around Z i.e. your code should be:
UPDATE Foo, Bar
SET Foo.B = Bar.B
WHERE Foo.A = CONCAT('Z', Bar.A);
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