更新&"order&"专栏MySQL? [英] Updating an "order" column MySQL?

查看:83
本文介绍了更新&"order&"专栏MySQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新订单"列的最佳方法是什么?

What's the best way to update an "order" column?

说我有一个ID列,其范围是0到9,而订购列的范围是0到9.

Say I have an id column with 0 to 9, and order column from 0 to 9.

当前,它在数据库中的位置为: 0 0,1 1,2 2,等等

Currently, it's in the database as: 0 0, 1 1, 2 2, etc

我的HTML页面发布了所需的新订单:0 8、1 3、2 6等(这完全是随机的,由用户决定).

My HTML page posts what it wants as the new order: 0 8, 1 3, 2 6, etc. (This is completely random, decided by the user).

进行更新的最佳方法是什么?

What's the best way to make the update?

我可以循环浏览并运行每个更新. 我还可以创建一个包含所有对的临时表,然后基于子查询进行更新.

I can loop through and run an update for each. I can also create a temporary table with all the pairs, and then update based on a subquery.

但是我觉得我忘记了一些琐碎的事情,这些事情会更快地做到这一点.有什么建议吗?

But I feel like I'm forgetting something trivial that will do this much faster. Any suggestions?

推荐答案

您必须自己更新每一行,无法在sql中进行映射"更新.

You have to update each row by itself, there is no way to do a "map" update in sql.

(有一些技巧,但无论如何在这里并没有实际应用/帮助.)

(There are some tricks but they don't really apply/help here anyway.)

这篇关于更新&"order&"专栏MySQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆