ユーザーの順序を変更できるクエリがあります。
ここに私のクエリがあります:
update test set orderID =
case orderID
when (select orderID from ( select * from test where orderID > ( select orderID from test where id = 'id I want to move up' ) limit 1) as nextOrderID ) then ( select orderID from ( select * from test where id = 'id I want to move up') as nextOrderID )
when ( select orderID from ( select * from test where id = 'id I want to move up' ) as nextOrderID ) then (select orderID from ( select * from test where orderID > ( select orderID from test where id = 'id I want to move up' ) limit 1) as nextOrderID )
else
orderID
end
そのクエリを実行するのにそれほど時間がかからないかどうかを知りたいのですが、そうであれば、ロードを高速化する方法と、そのクエリを減らすことは可能ですか?
アップデート:
コードを少し編集したので、クエリをより速く実行できると思います..ここにコードの一部があります:
$query = "
SELECT (
SELECT orderID
FROM test WHERE id = 'user id that i want to move up'
) AS user_order,
(
SELECT orderID
FROM test WHERE orderID > user_order
ORDER BY orderID
LIMIT 0,1
) AS nextUser_order
";
$result = mysql_query($query);
$data = mysql_fetch_assoc($result);
$query = "
UPDATE test SET orderID = IF(orderID='{$data[nextUser_order]}',
'{$data[user_order]}', '{$data[nextUser_order]}')
WHERE orderID IN ('{$data[nextUser_order]}', '{$data[user_order]}');
";
$result = mysql_query($query);