Skip to content

Instantly share code, notes, and snippets.

@ybart
Created June 12, 2011 16:25
Show Gist options
  • Save ybart/1021727 to your computer and use it in GitHub Desktop.
Save ybart/1021727 to your computer and use it in GitHub Desktop.
SELECT "rankings"."id", "rankings"."rank", "rankings"."progress", "rankings"."vote_count", "rankings"."vote_score", "rankings"."pal_count", "rankings"."pal_score", "rankings"."clip_id", "rankings"."jtop_id", "rankings"."prev_jtop_id"
FROM "clips", "rankings"
INNER JOIN "artists" ON "clips"."artist_id" = "artists"."id"
INNER JOIN "clips" ON "rankings"."clip_id" = "clips"."id"
WHERE "rankings"."jtop_id" = 80
GROUP BY "rankings"."id", "rankings"."rank", "rankings"."progress", "rankings"."vote_count", "rankings"."vote_score", "rankings"."pal_count", "rankings"."pal_score", "rankings"."clip_id", "rankings"."jtop_id", "rankings"."prev_jtop_id"
ORDER BY "artists"."name", "clips"."title";
ERROR: invalid reference to FROM-clause entry for table "clips"
LINE 1: ... FROM "clips", "rankings" INNER JOIN "artists" ON "clips"."a..
@ybart
Copy link
Author

ybart commented Jun 12, 2011

SELECT "rankings"."id", "rankings"."rank", "rankings"."progress", "rankings"."vote_count", "rankings"."vote_score", 
"rankings"."pal_count", "rankings"."pal_score", "rankings"."clip_id", "rankings"."jtop_id", "rankings"."prev_jtop_id" 
FROM "rankings" 
INNER JOIN "artists" ON "clips"."artist_id" = "artists"."id" 
INNER JOIN "clips" ON "rankings"."clip_id" = "clips"."id" 
WHERE "rankings"."jtop_id" = 80 
GROUP BY "rankings"."id", "rankings"."rank", "rankings"."progress", "rankings"."vote_count", "rankings"."vote_score", 
"rankings"."pal_count", "rankings"."pal_score", "rankings"."clip_id", "rankings"."jtop_id", "rankings"."prev_jtop_id" 
ORDER BY "artists"."name", "clips"."title";

ERROR: missing FROM-clause entry for table "clips"
LINE 1: ..._jtop_id" FROM "rankings" INNER JOIN "artists" ON "clips"."a...

@ybart
Copy link
Author

ybart commented Jun 12, 2011

The fixed query:

SELECT "rankings"."id", "rankings"."rank", "rankings"."progress", "rankings"."vote_count", "rankings"."vote_score", "rankings"."pal_count", "rankings"."pal_score", "rankings"."clip_id", "rankings"."jtop_id", "rankings"."prev_jtop_id" 
FROM "rankings" 
INNER JOIN "clips" ON "rankings"."clip_id" = "clips"."id" 
INNER JOIN "artists" ON "clips"."artist_id" = "artists"."id" 
WHERE "rankings"."jtop_id" = 80 
GROUP BY "rankings"."id", "rankings"."rank", "rankings"."progress", "rankings"."vote_count", "rankings"."vote_score", 
"rankings"."pal_count", "rankings"."pal_score", "rankings"."clip_id", "rankings"."jtop_id", "rankings"."prev_jtop_id",
"artists".name, "clips".title
ORDER BY "artists"."name", "clips"."title";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment