ISRO 2016 · SQL Queries

MCQ · 1 mark · Problem DBMS-SQL-0080

The relation book (title, price) contains the titles and prices of different books. Assuming that no two books have the same price, what does the following SQL query list?select title from book as B
where (select count(*)
       from book as T
       where T.price > B.price) < 5
  1. A
    Titles of the four most expensive books
  2. B
    Title of the fifth most inexpensive book
  3. C
    Title of the fifth most expensive book
  4. D
    Titles of the five most expensive books

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solution\[\boxed{\text{row kept} \iff \#\{\text{dearer books}\} < 5}\]For each book B the subquery counts the books dearer than B. The count is \(0, 1, 2, 3, 4\) for the five most expensive books and at least \(5\) for every other book.So the query lists the titles of the five most expensive books.Answer: D

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com