The relation book (title,price) contains the titles and prices of different…
2016
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
- A.
Titles of the four most expensive books
- B.
Title of the fifth most inexpensive book
- C.
Title of the fifth most expensive book
- D.
Titles of the five most expensive books
Attempted by 171 students.
Show answer & explanation
Correct answer: D
The subquery counts how many books have a price higher than the current book's price. If this count is less than 5, it means there are fewer than 5 books more expensive than the current one. This identifies the top 5 most expensive books.
A video solution is available for this question — log in and enroll to watch it.