Skip to content

Instantly share code, notes, and snippets.

@elieux
Created November 20, 2019 12:54
Show Gist options
  • Save elieux/9a1444df52ab48250d6e242aeffaf12d to your computer and use it in GitHub Desktop.
Save elieux/9a1444df52ab48250d6e242aeffaf12d to your computer and use it in GitHub Desktop.
Weird MySQL index thing
SELECT main.id, (
SELECT SUM(group_member.col)
FROM tbl AS group_member
WHERE main.id = group_member.id OR main.parent_id > 0 main.parent_id = group_member.parent_id
) AS col_sum
FROM tbl AS main
ORDER BY id DESC
LIMIT 50;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment