Book(bookID, ISBN, title, author, publish-year, category)
Member(memberID, lastname, firstname, address, phone-number, limit)
CurrentLoan(memberID, bookID, loan-date, due-date)
History(memberID, bookID, loan-date, return-date)
Members can borrow books from the library. The number of books they can borrow is limited by the “limit” field of the Member relation. The category of a book includes fiction, non-fiction, children’s and reference. The CurrentLoan table represents the information about books that are currently checked out. When the book is returned to the library, the record will be removed from CurrentLoad relation, and will be inserted into History relation with the return-date. A library may have more than one copy of the same book, in which case each copy has its own bookID, but all copies share the same ISBN.
(1) (4 pts) Find the ISBN and title of all the books authored by Arthur Miller.
(2) (8 pts) List the bookID and title of all the books that are currently checked out by John Smith. Do not use any natural join in this query.
(3) (8 pts) Find the first name and last name of the members who are either currently borrowing book “Da Vinci Code” or have borrowed it in the past.
(4) (8 pts) Find the memberID, first name, and last name of the members who have never borrowed any books.
(5) (8 pts) List the first and last names of members who have borrowed (either currently or in the past) all the books in the library that are authored by Arthur Miller. If some books authored by Arthur Miller have multiple copies, he or she must have borrowed at least one copy of each of Arthur Miller’s books.
(6) (4 pts) Find the total number of books for each category (write a single query for this question).
1)Answer
Select ISBN, title from book where author = Arthur Miller;
In above query we will get a list of books with title which are written by author named Arthur Miller and also we will get a list of ISBN related to these books.
2)Answer
first memberid should be the foreign key in book table.
select bookid , title from book b
inner join currentloan cl on cl.bookid = b.bookid
inner join member m on m.memberid,m. firstname , m.lastname = b.memberid
where m.firstname = john, m.lastname = smith;
In above query we will get a list of book id and title of all the books which are checked out by a member whose first name is john and last name is smith.I have used inner join and I have combined three tables ,there is a inner join of three tables . These tables are linked to each other by primary keys and foreign keys.
Get Answers For Free
Most questions answered within 1 hours.