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.
精彩评论