1

I neet to select TOP 2 products with Max Price.

ProductID   ProductName SupplierID  CategoryID  Unit    Price
1   Chais   1   1   10  bags    18
2   Chang   1   1   24 bottles      19
3   Aniseed Syrup   1   2   12 bottles      10

I have used:

Select TOP 2 *
from Products
where Price = (Select Max(Price) from Products);

But the result is just 1 row.

2 Answers 2

8

This will give you the top 2 max prices but if the same price is in there twice you would get the same value twice, but from your code above that is what it would do so assuming that is what you are looking for.

Select TOP 2 * from Products order by Price DESC
1
  • How would we fetch items with the top 2 prices, if we did want to see items past the tie.
    – Stevoisiak
    Commented Nov 17, 2020 at 16:22
1

You need order by clause :

select top (2) * 
from Products p 
order by price desc;

Not the answer you're looking for? Browse other questions tagged or ask your own question.