I have the following query:
SELECT script FROM d_stages WHERE id IN
(SELECT g.stage + :i FROM games g INNER JOIN sessions s ON
g.expired = 0 AND s.user = g.user AND s.token = :token)
- Inner SELECT looks for a user id in ‘sessions’ table by a given token, then for a non-expired game for that user.
- It returns the game stage, which is modified (incremented, decremented, or left with no modification, depending on :i value).
- Outer SELECT returns a unique script for the found stage from dictionary.
Obviously, the modified stage number (g.stage + :i) should be written back to the DB, since the game has evolved. I can replace SELECT script with SELECT script, g.stage + :i, and use the modified number in another (UPDATE) query, but maybe I can do the same within a single query?
My DBMS is mySQL 5.5.
Regards,
I think, there is only one way: