I have a database based around a library system and I am trying to enhance my knowledge of MYSQL querys.
I want to try and list the names of borrowers that have borrowed all of the book titles in the database.
The request that I need to strip down is
SELECT b.BorName
FROM Borrower b
JOIN Loan l ON l.BorId = b.BorId
JOIN BookCopy bc ON bc.BcId = l.BcId
JOIN BookTitle bt ON bt.BtId = bc.BtId
And I guess I need to use bt.BtName which is the name of each book in the query above as well as the sub query SELECT bt.BtName FROM BookTitle bt but I don’t any words or queries to do this with the entire list.
I need to compare the first table with every row in the second query but am yet to find a way to do so.
After collecting unique borrower-title combinations (with
DISTINCT), you can identify those borrowers with the number of booktitles equivalent to the total number of booktitles that exist usingGROUP BYandHAVING: