Due to a dodge Excel upload, we corrupted some data between rows 6800 and 7024. For these rows, the description value for each row needs move down to the next row.
I was thinking of something like:
UPDATE `llx_entrepot`
SET `description`= (
SELECT `description`
FROM `llx_entrepot`
WHERE `rowid` = `rowid` -1)
WHERE `rowid` >= 6800 AND `rowid` < 7025
However, this doesn't work. How can I fix this code to make the needed adjustment?
CodePudding user response:
You need a self-join so you can pair each row up with the following row.
UPDATE llx_entropot AS t1
JOIN llx_entropot AS t2 ON t1.rowid = t2.rowid - 1
SET t1.description = t2.description
WHERE t1.rowid BETWEEN 6800 AND 7025
