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]

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] Correct Answer Titles of the five most expensive books

Query

The outer query selects all titles from book table. For every selected book, the subquery returns count of those books which are more expensive than the selected book. 

No two books have the same price

book B :

Title

Price

A

10

B

20

C

30

D

40

E

50

F

60

G

70

H

80

 

book T:

Title

Price

A

10

B

20

C

30

D

40

E

50

F

60

G

70

H

80

 

Query

The where clause of the outer query will be true for the 5 most expensive books.

The outer query selects all titles from the book table. For every selected book, the subquery returns count of those books which are more expensive than the selected book. The where clause of outer query will be true for 5 most expensive book. For example count (*) will be 0 for the most expensive book and count(*) will be 1 for second most expensive book.

Example

count (*) will be 0 for the most expensive book and count(*) will be 1 for the second most expensive book.

Related Questions

A statement is given below in the question followed by three courses of actions numbered I, II and III. On the basis of the information given, you have to assume everything in the statement to be true, and then decide which of the following suggested courses of actions logically follow(s) for pursuing. Statement: Hindustan Unilever and Nestlé plan to selectively increase prices of their products to take into account higher crude oil and petrol costs, the rupee’s depreciation against the dollar and more expensive commodities such as wheat. If crude remains where it is and if the rupee has depreciated, of course, there are headwinds as far as costs are concerned. I. Nestlé India’s logistics providers are looking to renegotiate rates after record-high petrol and diesel prices. Nestlé declined to comment on when and by how much prices would increase.  II. Nestlé commented that HUL had dropped prices in November after the Goods & Services Tax was introduced last year and an increase in prices now would likely not hurt consumers.  III. Petrol prices have crossed Rs 90 a litre in Mumbai on increasing global prices of crude oil, of which India is a net importer, further impacted by the falling rupee. Crude derivatives, which are key inputs for FMCG companies, and petroleum derivatives used in packaging material including bottles and tubes, have also become more expensive.