Skip to content

Instantly share code, notes, and snippets.

@MostlyFocusedMike
Created April 28, 2018 22:23
Show Gist options
  • Save MostlyFocusedMike/02785150d306a024d09d4d76a116b0cd to your computer and use it in GitHub Desktop.
Save MostlyFocusedMike/02785150d306a024d09d4d76a116b0cd to your computer and use it in GitHub Desktop.
SELECT SUM(cats.net_worth)
FROM owners
INNER JOIN cats_owners
ON owners.id = cats_owners.owner_id
JOIN cats ON cats_owners.cat_id = cats.id
WHERE cats_owners.owner_id = 2;
# which will return the following
SUM(cats.net_worth)
-------------------
1181600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment