edited by
31,003 views
70 votes
70 votes

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. Titles of the four most expensive books
  2. Title of the fifth most inexpensive book
  3. Title of the fifth most expensive book
  4. Titles of the five most expensive books
edited by

5 Answers

1 votes
1 votes

${\color{Blue} 5} $ ${\color{Blue} most} $ ${\color{Blue}expensive } $ ${\color{Blue}books } $

Just make a random table, and then, use two pointers T and B, now, just iterate the T pointer for each of B pointer

You will realise, this is like a nested for loop implementation.

This property is the soul of nested sub queries

You have to take example and solve

Now How easy it becomes

 

Thanks

Shashank

Answer:

Related questions

38 votes
38 votes
1 answer
2
Kathleen asked Sep 23, 2014
17,046 views
Consider the join of a relation $R$ with a relation $S$. If $R$ has $m$ tuples and $S$ has $n$ tuples then the maximum and minimum sizes of the join respectively are$m+n$...
33 votes
33 votes
4 answers
4
Kathleen asked Sep 11, 2014
14,130 views
A clustering index is defined on the fields which are of typenon-key and orderingnon-key and non-orderingkey and orderingkey and non-ordering