Skip to content

Instantly share code, notes, and snippets.

View MostlyFocusedMike's full-sized avatar

Mike Cronin MostlyFocusedMike

View GitHub Profile
TABLE: cats
id name age breed net_worth
---------- ---------- ---------- ------------- ----------
1 Maru 3 Scottish Fold 1000000
2 Hana 1 Tabby 21800
3 Grumpy Cat 4 Persian 181600
4 Lil\' Bub 2 Tortoiseshell 2000000
===============================================================
||
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)
-------------------