Reputation: 385
I have two tables: loan and librarian.
librarian: idLibrarian, libName and libPassword loan: idLoan,...,idLibrarian
Each loan has a idLibrarian. What I'm trying to do is find which librarian has the most loans. I can count number of librarians and number of loans. But i can't figure out how to group all the loans by idLibrarian and find the one with the highest amount of loans.
Upvotes: 0
Views: 131
Reputation: 27614
select idLibrarian, count(*) from loan group by idLibrarian order by 2 desc
First row will be the librarian with the most loans, etc.
Upvotes: 1