Denis
Denis

Reputation: 189

Select TOP 2 maximum values in SQL

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.

Upvotes: 1

Views: 24992

Answers (2)

Yogesh Sharma
Yogesh Sharma

Reputation: 50173

You need order by clause :

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

Upvotes: 1

Brad
Brad

Reputation: 3616

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

Upvotes: 8

Related Questions