Week 02 Excercises
Week 02 Excercises
1) Create Books Table: This table stores information about books, such as
BookID, Title, AuthorID (foreign key referencing the Authors table), PublisherID
(foreign key referencing the Publishers table), PublishedYear, ISBN number
(unique), and Price.
2) Create Authors Table: This table stores information about authors, such as
AuthorID, AuthorName, DOB, and Nationality.
3) Create Publishers Table: This table stores information about publishers, such
as PublisherID, PublisherName, and Address.
4) Insert the given data into Books Table: (1, 'The Great Gatsby', 1, 1, 1925,
'9780743273565', 10.99), (2, 'To Kill a Mockingbird', 2, 2, 1960,
'9780061120084', 7.99), (3, 'Pride and Prejudice', 4, 4, 1813, '9780141439518',
8.49), (4, 'The Catcher in the Rye', 5, 5, 1951, '9780316769488', 8.99), (5,
'Harry Potter and the Philosopher's Stone', 7, 7, 1997, '9780747532743',
12.99), (6, 'The Lord of the Rings', 8, 8, 1954, '9780544003415', 14.99);
5) Insert the given data into the Authors table: (1, 'F. Scott Fitzgerald', '1896-
09-24', 'American'), (2, 'Harper Lee', '1926-04-28', 'American'), (3, 'George
Orwell', '1903-06-25', 'British'), (4, 'Jane Austen', '1775-12-16', 'British'), (5, 'J.D.
Salinger', '1919-01-01', 'American'), (6, 'Herman Melville', '1819-08-01',
'American'), (7, 'J.K. Rowling', '1965-07-31', 'British'), (8, 'J.R.R. Tolkien', '1892-
01-03', 'British')
6) Insert the given data into the Publishers table: (1, 'Scribner', '123 Main St,
New York, NY'), (2, 'J.B. Lippincott & Co.', '456 Elm St, Philadelphia, PA'), (4,
'T. Egerton', '789 Oak St, London, UK'), (5, 'Little, Brown and Company', '567
Pine St, Boston, MA'), (7, 'Bloomsbury Publishing', '890 Maple St, London,
UK'), (8, 'Allen & Unwin', '901 Cedar St, Sydney, Australia');
Exercises
SQL Join
1. Write a query to combine rows from the Books table with matching rows from the
Authors table based on “AuthorID”?
2. Write a query to retrieve the “title” of the book and the corresponding “author name”.
3. Perform a LEFT JOIN between the Books and Publishers tables to list all books with
their Title, PublisherName, and Address.
4. Write a SQL query to retrieve the title of each book along with its author's name for all
books published after the year 1997.
5. Write a SQL query for the RIGHT JOIN between Books and Authors.
6. Write a SQL query to retrieve the title of each book along with the name of its author and
publisher.