开发者

What is the best way to update column1 value from record containing max(column2)?

开发者 https://www.devze.com 2023-03-06 19:37 出处:网络
I came up with this solution: UPDATE sessions SET time_stop = now() WHERE time_start = (SELECT max(time_start) FROM sessions);

I came up with this solution:

UPDATE sessions
SET time_stop = now()
WHERE time_start = (SELECT max(time_start) FROM sessions);

开发者_JAVA百科However, I have the feeling that it is not the optimal way of doing it. I would be interested in other, better ways of achieving the same result.

Thank you.

PS: if you feel there is no better way, please say so too.


I hardly see a way to optimize this query apart from setting up an index on sessions.time_start.

0

精彩评论

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