Skip to content

Instantly share code, notes, and snippets.

@FernandoBasso
Created August 14, 2015 13:54
Show Gist options
  • Save FernandoBasso/c6631edbd6afc633e2cd to your computer and use it in GitHub Desktop.
Save FernandoBasso/c6631edbd6afc633e2cd to your computer and use it in GitHub Desktop.
Three-table sql join
-- I have the tables `category`, `subscription` and `document`. Document
-- references subscription, and subscription references category. I am trying to
-- get the category name based on a documents PK. I am doing something like this:
SELECT category_name FROM categorias
INNER JOIN subscription ON category_fk = category_pk
INNER JOIN documents ON subscription_fk = document_pk
AND document_pk = 14;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment