I have a table with 3 columns: Animal, key, owner. Example
Cat 1 Bob
Bird 2 Bob
dog 3 Bob
dog 4 Andy
Lizard 5 Andy
Bird 6 Andy
Cat 7 Andy
and one related table per animal (columns key, weight). For example, table CAT_WEIGHT:
1 12
7 17
I want to find the Min, Max, Average, Total, and Count for each animal type, but only for a particular owner.
Is this possible to calculate these using a single MYSQL query? I know I can do it in multiple queries but am looking for the best way.
Thanks
Yes it is possible to do this using just one query.
All other things being equal you want to use as few queries as possible. Roundtrips to the database are generally some of the more expensive things you’ll encounter in programs.