tom22london
Programmer
following are the three queries but its too long however answer is alright, but is there any way to make these query shorter
Following are the tables (Feilds with star are primary keys)
Borrower(bor_id*, bor_name, bor_maxbooks)
Book_title(bt_id*, bt_name,pub_id, value)
Book_copy(bc_id*, bt_id, date acquired)
Loan(bor_id, bc_id, date_out, date_due, date_back)
Publisher(pub_id*, pub_name, pub_address)
Author(author_id*, author_name)
Authorship(author_id, bt_id)
1.
select bor_name from borrower
where bor_id in
(select bor_id from loan
where bc_id in
(select bc_id from book_copy
where bt_id in
(select bt_id from book_title
where bt_id in
(select bt_id from authorship
where authorship.author_id in
(select author_id from author
where author.author_name = 'Roald Dahl')))))
2.select bor_name from borrower
where bor_id not in
(select bor_id from loan
where bc_id not in
(select bc_id from book_copy
where bt_id not in
(select bt_id from book_title
where bt_id not in
(select bt_id from authorship
where authorship.author_id not in
(select author_id from author
where author.author_name = 'Roald Dahl')))))
3. select bt_name from book_title bt1
where pub_id in
(select pub_id from publisher
where pub_id in
(select pub_id from book_title bt2
where bt2.bt_name='The Twits')) and bt_name <> 'The Twits'
Following are the tables (Feilds with star are primary keys)
Borrower(bor_id*, bor_name, bor_maxbooks)
Book_title(bt_id*, bt_name,pub_id, value)
Book_copy(bc_id*, bt_id, date acquired)
Loan(bor_id, bc_id, date_out, date_due, date_back)
Publisher(pub_id*, pub_name, pub_address)
Author(author_id*, author_name)
Authorship(author_id, bt_id)
1.
select bor_name from borrower
where bor_id in
(select bor_id from loan
where bc_id in
(select bc_id from book_copy
where bt_id in
(select bt_id from book_title
where bt_id in
(select bt_id from authorship
where authorship.author_id in
(select author_id from author
where author.author_name = 'Roald Dahl')))))
2.select bor_name from borrower
where bor_id not in
(select bor_id from loan
where bc_id not in
(select bc_id from book_copy
where bt_id not in
(select bt_id from book_title
where bt_id not in
(select bt_id from authorship
where authorship.author_id not in
(select author_id from author
where author.author_name = 'Roald Dahl')))))
3. select bt_name from book_title bt1
where pub_id in
(select pub_id from publisher
where pub_id in
(select pub_id from book_title bt2
where bt2.bt_name='The Twits')) and bt_name <> 'The Twits'