Skip to content
Advertisement

I’m unable to get result using this query

create table Item
(
    Itemid int primary key ,
    ItemName varchar(100),
    CalorificValue int,
    price int 
)

enter image description here

Task: what item has the highest price followed by the highest calorific value?

My query solution:

Select Itemname 
from Item 
where price = (Select max(price) from Item)
  and CalorificValue = (Select max(CalorificValue) from Item)

But I’m not getting the answer. Can anyone solve this issue?

Advertisement

Answer

Try the following with limit

select
    TOP 1 ItemName
from yourTable
order by
    price desc,
    CalorificValue desc
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement