Skip to content

Instantly share code, notes, and snippets.

@nizom333
Forked from hackimov/GROUP_MAXIMUM.SQL
Created May 31, 2021 06:26
Show Gist options
  • Save nizom333/498970d5edf4f940bda58d0274dac750 to your computer and use it in GitHub Desktop.
Save nizom333/498970d5edf4f940bda58d0274dac750 to your computer and use it in GitHub Desktop.
#SQL #MAXIMUM #WITHOUT_GROUP_BY #SPEED #QUERY
SELECT maintable.*
FROM TABLE_NAME maintable
LEFT OUTER JOIN TABLE_NAME temporarytable
ON maintable.GROUPING_BY_COLUMN = temporarytable.GROUPING_BY_COLUMN
AND maintable.COLUMN_WHERE_THE_MAXIMUM_IS_NEEDED < temporarytable.COLUMN_WHERE_THE_MAXIMUM_IS_NEEDED
WHERE temporarytable.COLUMN_WHERE_THE_MAXIMUM_IS_NEEDED IS NULL
ORDER BY PRIMARY_KEY_COLUMN DESC
LIMIT 50;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment