Reputation: 3
I am trying to write a select query where, I need the Title and Max of Cost in a table;
Any help on this would be really appreciated, thanks!
1) Below query is giving me the all the columns
select Title, MAX(sold)
from software
Group by Title, sold;
2) Below query is giving me the right result but here I'm hard coding the highest value in 'Sold' column
select Title, sold
from software
where sold = '84';
Upvotes: 0
Views: 46
Reputation: 1362
You were close. When you are aggregating a field you generally don't want to group by it as well.
This should work for you:
select Title, MAX(sold)
from software
Group by Title;
Upvotes: 0
Reputation: 332
You can try to query something like this which would give the details of max value record in table.
select * from software where sold = (select MAX(sold)from software)
Hope this was helpful.
Upvotes: 1
Reputation: 37473
You can try below -
select Title, sold from software where sold=(select MAX(sold) from software))
Upvotes: 0