开发者

Updating a table in a Mysql database

开发者 https://www.devze.com 2023-02-09 23:25 出处:网络
Let\'s sa开发者_运维知识库y I havein a table named threadloc: idthread 41 32 23 14 for a table I want to change the table value of thread so that I can pick any thread and put in on the bottom (id

Let's sa开发者_运维知识库y I have in a table named threadloc:

id  thread
4   1
3   2
2   3
1   4

for a table

I want to change the table value of thread so that I can pick any thread and put in on the bottom (id 1) and push all the other threads up one.

So like I pick 2 it would be:

id  thread
4   1
3   3
2   4
1   2


UPDATE threadloc SET ID = ID + 1 WHERE thread <> @currentThread AND ID < @currentID;
UPDATE threadloc SET ID = 1 WHERE thread = @currentThread

edit: now it doesn't change higher IDs

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号