Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Created August 7, 2017 14:51
Show Gist options
  • Save yorickpeterse/3f444fd973c38cf933301156459252c9 to your computer and use it in GitHub Desktop.
Save yorickpeterse/3f444fd973c38cf933301156459252c9 to your computer and use it in GitHub Desktop.
-- Before
SELECT "namespaces".*
FROM "namespaces"
WHERE "namespaces"."type" IN ('Group')
AND "namespaces"."id" = 2
AND "namespaces"."type" IN ('Group')
AND "namespaces"."type" = 'Group'
ORDER BY "namespaces"."id" DESC
LIMIT 1;
-- This is really all we need to achieve the exact same result:
SELECT namespaces.*
FROM namespaces
WHERE namespaces.id = 2
-- This is because "id" is a unique value, so if you know what ID you
-- are looking for you will never get a row that you didn't expect,
-- meaning the "type" WHEREs are completely pointless.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment