I'm having issues creating a query which may auto-fill the value (only specific columns) based on the values in the following row, when the first field of both row has got the same value.
The situation is the following, I'll try my best to explain myself with a simple image.
Is there someone who can help me? I'm not very good in SQL.
CodePudding user response:
Use a self-join to copy from the row that has the columns filled in to the row with blank values.
UPDATE yourTable AS t1
JOIN yourTable AS t2 ON t1.code = t2.code
SET t1.rating = t2.rating, t1.address = t2.address, ... and so on for all columns
WHERE t1.rating = '' AND t2.rating != ''