Hello,
I am trying to work on my SQL database that I've set up that is supposed to be exampling a library system.
Document(document#, document_title, document_type, document_descriptors)
Borrowing(reader#, document#, copy#, date_borrowed, date_returned)
I'm supposed to put through a query that returns the document(s) that is(are) the most borrowed. I would have to compare the copy#'s to see what document_title has the most copy# that have a copy_status of 'borrowed'. How exactly would I do this in SQL?
So far I have the following:
Code:
SELECT D.document_title, COUNT(*) as "Times borrowed"
FROM Document D, Borrowing B
WHERE D.`document#` = B.`document#`
GROUP BY D.document_title
ORDER BY COUNT(*) DESC LIMIT 1
This gives me the highest borrowed document, but if there were two I wouldn't see that because of the limit. Is there anyway to alter this to show which document(s) is(are) the most borrowed?