- Pet (pid, name, age, species, breed)
- Owner (oid, first_name, last_name, age, address, phone, email)
- Owns (pid, oid)
- Owns.pid is a foreign key that references Pet.pid
- Owns.oid is a foreign key that references Owner.oid
Last active
December 31, 2015 22:59
-
-
Save GEverding/8057060 to your computer and use it in GitHub Desktop.
Example SQL Query to find all the records with the maximum value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
oid, count(distinct pid) | |
from | |
owns | |
group by oid | |
having count(distinct pid) >= (select | |
T.max | |
from | |
(select | |
oid, count(distinct pid) as max | |
from | |
owns | |
group by oid | |
order by max desc | |
limit 1) as T) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment