I have following query
select id, nameOfPet, count(fed)
from petLover, pets
where id = 180 and petLover.nameOfPet = pets.nameOfPet
group by fed
order by fed desc;
So what the query does is get a person’s id, get all the names of the pets he has, looks in the table pets for the same person and checks which pet has been fed how many times and output the person’s id, the name of the pet and how often it has been fed.
Now I want to only output the pet that has been fed the most. I could certainly use limit 1, but I want to output all, if the number of feeding is the same for several pets.
The nested query derived the counts. Other than having only a single column it is identical to the outermost query.