mysql procedure to update numeric reference in previous rows when one is updated
Posted
by markcial
on Stack Overflow
See other posts from Stack Overflow
or by markcial
Published on 2010-03-16T11:41:17Z
Indexed on
2010/03/16
11:46 UTC
Read the original article
Hit count: 245
There's a table like this one
______________________ | id | title | order | |----------------------| | 1 | test1 | 1 | |-----|--------|-------| | 2 | test2 | 2 | |-----|--------|-------| | 3 | test3 | 3 | |-----|--------|-------| | 4 | test4 | 4 | '----------------------'
when i introduce in my mysql shell a single update to a row
$sql> UPDATE `table` SET order=1 WHERE id=3;
And then procedure or method resamples order column in the before update lower values to get its order renewed like this
______________________ | id | title | order | |----------------------| | 1 | test1 | 2 | |-----|--------|-------| | 2 | test2 | 3 | |-----|--------|-------| | 3 | test3 | 1 | |-----|--------|-------| | 4 | test4 | 4 | '----------------------'
Any help would be appreciated, thanks!
© Stack Overflow or respective owner