SQL Exercise with Solution / Exercises involving JOIN, Subqueries, Group By, Having, etc
|Figure 4.6 - A relational database schema for a library database - Taken from Fundamentals of database systems by Elmasri and Navathe|
- How many copies of the book titled The Lost Tribe are owned by the library branch whose name is "Sharpstown"?
- How many copies of the book titled The Lost Tribe are owned by each library branch?
- Retrieve the names of all borrowers who do not have any books checked out .
- For each book that is loaned out from the "Sharpstown" branch and whose DueDate is today, retrieve the book title, the borrower's name, and the borrower's address.
- For each library branch, retrieve the branch name and the total number of books loaned out from that branch.
- Retrieve the names, addresses, and number of books checked out for all borrowers who have more than five books checked out.
- For each book authored (or co-authored) by "Stephen King", retrieve the title and the number of copies owned by the library branch whose name is "Central"
SELECT B.Title, R.Name, R.Address
SELECT L.BranchName, COUNT(*)
SELECT B.Name, B.Address, COUNT(*)