Skip to content

Instantly share code, notes, and snippets.

@MostlyFocusedMike
Created April 29, 2018 04:32
Show Gist options
  • Save MostlyFocusedMike/302c083286634098db7c6c45a772af5f to your computer and use it in GitHub Desktop.
Save MostlyFocusedMike/302c083286634098db7c6c45a772af5f to your computer and use it in GitHub Desktop.
SELECT *
FROM owners
INNER JOIN cats_owners
ON owners.id = cats_owners.owner_id
INNER JOIN cats
ON cats_owners.cat_id = cats.id;
# returns
id name cat_id owner_id id name age breed net_worth
---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
2 Sophie 3 2 3 Grumpy Cat 4 Persian 181600
3 Penny 3 3 3 Grumpy Cat 4 Persian 181600
2 Sophie 1 2 1 Maru 3 Scottish 1000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment