Skip to content

Instantly share code, notes, and snippets.

@mickhansen
Created May 25, 2014 10:00
Show Gist options
  • Save mickhansen/82c83cf11d149469b122 to your computer and use it in GitHub Desktop.
Save mickhansen/82c83cf11d149469b122 to your computer and use it in GitHub Desktop.
SELECT "Comics".*,
"Favourites"."id" AS "Favourites.id",
"Favourites"."createdAt" AS "Favourites.createdAt",
"Favourites"."updatedAt" AS "Favourites.updatedAt",
"Favourites"."UserId" AS "Favourites.UserId",
"Favourites"."ComicId" AS "Favourites.ComicId"
FROM (
SELECT "Comics".* FROM "Comics" ORDER BY "number" DESC LIMIT 60
) AS "Comics"
LEFT OUTER JOIN "Favourites" AS "Favourites"
ON "Comics"."id" = "Favourites"."ComicId" AND "Favourites"."UserId"=37
ORDER BY "Comics"."number" DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment