recategorized by
1,886 views
0 votes
0 votes

Consider a relation book (title, price) which contains the titles and prices of different books. Assuming that no two books have the same price, what does the following SQL query?

Select title
from book as B
where (select count(*)
    from book as T
    where T.price > B. price < 7
  1. Titles of the six most expensive books
  2. Title of the sixth most expensive books
  3. Titles of the seven most expensive books
  4. Title of the seventh most expensive books
recategorized by

2 Answers

1 votes
1 votes
query will give title of seven most expensive books i.e option C

query is doing nothing just giving title of those books which are cheaper than 6 books atmost.

Like for example you have books in prices range

100,200,300,400,500,600,700,800

now for 100 as there are 7 books which satisfy above condn so condn becomes false so title with book 100 is not included ....rest for all it comes out to be true so it gives output as 200,300,400,500,600,700,800 as output  which are nothing but seven most expensive books.!
0 votes
0 votes
Answer C

The Query returns titles of the seven most expensive books.

We can see that titles of those book from 'B' will be retrieved if the inner query has count value from 0 to 6.

Count 0 indicates the most expensive book (no other book from T is more expensive than it). Count 1 indicates the second most expensive book an so on.

Related questions

0 votes
0 votes
5 answers
1
Pooja Khatri asked Jul 13, 2018
2,305 views
In RDBMS, which type of Join returns all rows that satisfy the join condition?Inner JoinOuter JoinSemi JoinAnti Join