开发者

Updating a table in a Mysql database

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜