I am trying to update a column in the mainDB table, based on data in the engine table. The date in the main DB table is stored in (YYYY-MM_DD) format and I want to subtract only the year
I’m not sure how to properly join these two tables to update the percentage
UPDATE maindb
JOIN engine ON engine.COL_3 = CONCAT(maindb.COL_1,"-", SUBSTRING_INDEX(maindb.COL_2,"-",-1))
SET Maindb.COL_3 = engine.COL_4,
2
Answers
Your join condition is off. I think you want:
I suspect that
m.COL_2
is text, in which case the above should work. It should be a date, in which case we should extract the year and then cast to text before comparing to the the other table.What is the data types of the fields?
There are different solutions for different data types
If all fields is
varchar
If maindb.COL_2 is
date