Skip to content

Instantly share code, notes, and snippets.

@aslakknutsen
Created March 9, 2017 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aslakknutsen/bc393aec69d4a9e9aac009abff1ae77b to your computer and use it in GitHub Desktop.
Save aslakknutsen/bc393aec69d4a9e9aac009abff1ae77b to your computer and use it in GitHub Desktop.
Order of execution in a single SQL
UPDATE work_items set execution_order = (
SELECT
(
(
SELECT execution_order
FROM work_items
WHERE id = '12262'
)
+
(
SELECT execution_order
FROM work_items
WHERE execution_order < (
SELECT execution_order
FROM work_items
WHERE id = '12938'
)
ORDER BY execution_order DESC
LIMIT 1
)
)
/2
)
WHERE id = 12938;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment