Test Index
CBSE Class 12 Computer Science 2026 Paper Compartment
© examsnet.com
Question : 34 of 37
Marks:
+1,
-0
Consider a database LIBRARY_CATALOG containing the following two tables – PUBLISHERS and BOOKS given below :Table : PUBLISHERS
Table : BOOKS
Note : The attribute Pages in the table BOOKS represents the total number of pages in a book, PublID represents the Publisher's Identification Number, PublYear represents the Year of Publication.Write the SQL queries for the following :(I) (a) To display Title of all BOOKS and their corresponding PublYear which belong to the 'Fiction' type of Genre (from PUBLISHERS table) through Equi Join.OR(b) To display Title of all BOOKS and their corresponding PublYear which belong to the 'Fiction' type of Genre (from PUBLISHERS table) through Natural Join.(II) To display Name of all PUBLISHERS and their corresponding Title of BOOKS in ascending order of PublYear.(III) To delete all records from the table BOOKS whose PublYear is older than 2020.(IV) To open the database LIBRARY_CATALOG and then display the names of all tables present in the database.
| PublID | Name | Country | Genre |
| 101 | Grand Books | USA | Fiction |
| 102 | World Lit Press | UK | Non-Fiction |
| 103 | Tech Tome | Germany | Sci-Fi |
| 104 | Story Weaver | USA | Fiction |
| 105 | Global Insights | Canada | Non-Fiction |
| BookID | Title | PublID | PublYear | Pages |
| 3001 | The Last Horizon | 101 | 2018 | 450 |
| 3002 | Echoes of Tomorrow | 103 | 2020 | 320 |
| 3003 | A Brief History | 102 | 2015 | 580 |
| 3004 | Whispers in the Wind | 101 | 2019 | 280 |
| 3005 | Starship Odyssey | 103 | 2021 | 400 |
| 3006 | The Silent Shore | 104 | 2022 | 350 |
| 3007 | Understanding AI | 103 | 2019 | 290 |
Solution:
Concept: The common column of the two tables is PublID. An equi join names both tables and matches them with an explicit equality condition in WHERE; a natural join matches automatically on the columns that have the same name (here only PublID) and shows that column once.(I)(a) Equi Join:
(II) Join on PublID and sort by PublYear (ascending is the default):
SELECT Title, PublYearFROM BOOKS, PUBLISHERSWHERE BOOKS.PublID = PUBLISHERS.PublID AND Genre = 'Fiction';OR (I)(b) Natural Join:
SELECT Title, PublYearFROM BOOKS NATURAL JOIN PUBLISHERSWHERE Genre = 'Fiction';Either query gives the books of publishers 101 and 104:
| Title | PublYear |
| The Last Horizon | 2018 |
| Whispers in the Wind | 2019 |
| The Silent Shore | 2022 |
SELECT Name, TitleFROM PUBLISHERS P, BOOKS BWHERE P.PublID = B.PublIDORDER BY PublYear;(The first row is World Lit Press, A Brief History (2015) and the last is Story Weaver, The Silent Shore (2022).)(III) "Older than 2020" means published before 2020, i.e. PublYear < 2020 (2020 itself is not older).
DELETE FROM BOOKSWHERE PublYear < 2020;(This removes books 3001, 3003, 3004 and 3007.)(IV) USE selects (opens) a database; SHOW TABLES lists the tables in the current database.
USE LIBRARY_CATALOG;SHOW TABLES;Key point: In an equi join the join condition (
BOOKS.PublID = PUBLISHERS.PublID) must be written; without it every book is paired with every publisher (a Cartesian product).© examsnet.com
Go to Question: