Sheet 2
Sheet 2
Instructions
For this exercise, you will perform the following tasks on a database named LibraryDB.
Complete each task as described. Write the SQL queries to execute the operations.
Page 1 of 7
Practice Sheet- 2 (SQL)
2. Insert at least 5 authors into the Authors table with values for all columns.
Page 2 of 7
Practice Sheet- 2 (SQL)
1. Use the GROUP BY clause to find the number of books in each genre.
2. Use the DISTINCT keyword to find all unique genres in the database.
3. Write a query using AND, OR, and NOT to retrieve books published after 2000 that are
either in the "Fiction" genre or not written by "Jane Austen".
4. Use aggregate functions (e.g., SUM, AVG, MAX, MIN) to calculate:
o The average number of available copies across all books.
o The maximum number of available copies for any book.
5. Write a query using a wildcard (LIKE) to find all books with titles starting with the letter
"P".
6. Retrieve books where the PublishedYear is between 1900 and 2000 using the
BETWEEN operator.
7. Retrieve books with Genre values in a specified list (e.g., "Fiction", "Romance") using
the IN operator.
8. Perform an inner join between two tables (Books and Authors, where Authors
contains additional details about authors) to retrieve books along with author details.
9. Use the HAVING clause to filter genres that have more than 5 books in total.
10. Write a query using the EXISTS operator to check if there are any books with less than
3 available copies.
Page 3 of 7