21ZC52- Database Technologies Laboratory
Dharun kanna N (23MZ01)
Exp 3
I. Joins-and Correlations :
40. Find out the book number which has been issued to ‘Jeeva’.
SELECT T.book_id,M.fname|| ' ' ||M.lname AS Name FROM member M JOIN transaction T ON
T.member_id = M.member_id WHERE lname='Jeeva';
41. Find the names and book numbers of all the members who have been Issued a book.
SELECT M.fname || ' ' || M.lname AS Name , T.book_id FROM member M JOIN transaction T ON
M.member_id = T.member_id;
42. Select the title, member_id, book_id for all the books that are issued.
SELECT B.title , T.member_id , T.book_id FROM books B JOIN transaction T ON B.book_id =
T.book_id ;
43. Find out the title and types of the books that have been issued to ’Neeraj’.
SELECT B.title , B.type FROM books B JOIN transaction T ON B.book_id = T.book_id WHERE
T.member_id = (SELECT member_id FROM member WHERE lname='Neeraj');
44. Find the names of customers who have been issued book of type"CSE’.
SELECT M.fname|| ' ' || M.lname AS Name FROM member M JOIN transaction T ON
M.member_id = T.member_id WHERE T.book_id IN (SELECT book_id FROM books WHERE
type='CSE');
45. Display the title, lname, fname for members having book number greater than or equal to B00007,
in the followmg format : The book taken by {fname} {lname} is {title}.
SELECT 'This book taken by ' || M.fname || ' ' || M.lname|| ' is '|| B.title AS Records FROM
member M JOIN transaction T ON M.member_id = T.member_id JOIN books B ON T.book_id =
B.book_id WHERE T.book_id >= 'B00007';
II. Nested Queries :
46. Find out which members have been issued book number B00009.
SELECT M.member_id , M.fname , B.title FROM member M JOIN transaction T ON
M.member_id = T.member_id JOIN books B ON T.book_id = B.book_id WHERE B.book_id
= 'B00009';
47. Find the member name and area with transaction number ’t06‘.
SELECT M.fname,M.area FROM member M where M.member_id = (SELECT T.member_id
FROM transaction T WHERE T.t_id = 'T06');
48. Find the member names and phone numbers who have been issued books before the month
of August.
SELECT M.fname, M.phone_no FROM member M WHERE member_id IN (SELECT
T.member_id FROM transaction T WHERE to_char(T.issue_date,'MM') < '08') ;
49. Find the name of the books issued to ‘George’ and ‘Basu’.
SELECT book_id,title FROM books WHERE book_id IN (SELECT book_id FROM transaction
WHERE member_id IN (SELECT member_id FROM member WHERE lname='George' OR
fname='Basu'));
50. Find the type and book number of books issued to member_id ’M0l’ and “M06'.
SELECT B.book_id, B.title , B.type FROM books B WHERE B.book_id IN (SELECT
T.book_id FROM transaction T WHERE T.member_id IN ('M01','M06'));
51. Find out. if the book having author “R P Jain” is issued to any member and print the member
id to whom it is issued.
SELECT M.member_id FROM member M WHERE M.member_id IN (SELECT
T.member_id FROM transaction T WHERE T.book_id IN (SELECT B.book_id FROM
books B WHERE B.author='R P Jain'));
52. Find the lname, fname who have been issued books.
SELECT M.fname || ' ' || M.lname AS Books_Issued FROM member M WHERE
M.member_id IN (SELECT DISTINCT(T.member_id) FROM transaction T );
III. Union / Intersection / Set Difference
53. Find the members who have taken the book of type either CSE or ECE or both.
SELECT M.member_id , M.fname FROM member M WHERE M.member_id IN (SELECT
T.member_id FROM transaction T WHERE T.book_id IN ( SELECT B.book_id FROM books B
WHERE B.type IN ('CSE')))
UNION
SELECT M.member_id , M.fname FROM member M WHERE M.member_id IN (SELECT
T.member_id FROM transaction T WHERE T.book_id IN ( SELECT B.book_id FROM books B
WHERE B.type IN ('ECE')));
54. Display all the members who have been issued the books ‘Computer System Architecture’
and ‘An Introduction To Distributed And Parallel Computing’.
SELECT T.member_id FROM transaction T WHERE T.book_id IN ( SELECT B.book_id FROM
books B WHERE B.title='Computer System Architecture')
UNION
SELECT T.member_id FROM transaction T WHERE T.book_id IN ( SELECT B.book_id FROM
books B WHERE B.title='An Introduction To Distributed And Parallel Computing');
55. Find all the names of members except those members who are staying in area ‘CBE’
SELECT fname || ' ' || lname AS Name FROM member WHERE area NOT IN ('CBE');
IV. Views:
56. Create a view to get a number of books and average price of the books which are taken by each
customer.
CREATE VIEW book_data AS SELECT T.member_id ,COUNT(B.book_id) AS Count ,
AVG(B.price) AS Average FROM transaction T ,books B WHERE B.book_id = T.book_id
GROUP BY T.member_id;
57. Create a view to display the name of the member, title and price of the books to whom it is
Issued.
SELECT M.fname || M.lname AS Name, B.title, B.price FROM transaction T , books B ,
member M WHERE T.member_id = M.member_id AND T.book_id = B.book_id ;
V. File Updation:
58. Change the telephone number of Sneha to 7865466389.
UPDATE member SET phone_no='7865466389' WHERE lname='Sneha';
59. Change the issue__date of member_id ‘M01’ to 24/07/93.
UPDATE transaction SET issue_date='24-JUL-93' WHERE member_id='M01';
60. Change the price of Data Structures Using C And C++’ to Rs.1250.00.
UPDATE books SET price=1250 WHERE title ='Data Structures Using C and C++';
61. Delete the record with transaction id t08 from the transaction table.
DELETE FROM transaction WHERE t_id='T08';
62. Delete all the records having return date before 10th July ’93.
DELETE FROM transaction WHERE return_date < '10-JUL-93';
63. Change the area of member id ‘M04’ to ‘DEL’.
UPDATE member SET area='DEL' WHERE member_id = 'M04';
64. Change the return date of transaction id t09 to ‘16-08-93’.
UPDATE transaction SET return_date='16-AUG-93' WHERE t_id='T09';