Let's say I have a OrderDetails table like shown here (click on OrderDetails table on the right) https://www.w3schools.com/sql/trysql.asp?filename=trysql_op_in
I want to select productID with max number of quantity
I went thru this answer Is it possible to use Aggregate function in a Select statment without using Group By clause?,
so this answer makes sense if I am summing/averaging something then putting the other column(without aggregation) in a group by clause
for example
select depName, avg(salary)
from department
here you're averaging without group by so the query is ambiguous that avg of what depName ?
but the following query is what I am talking about if I have a situation like this (OrderDetails table and select ID of max quantity) can I use the below query ?
select ProductID, max(Quantity)
from
OrderDetails
the query shown above gives me desired result, it gives me the ID which has the max quantity. I know there are other ways of performing the same query like put them and desc. order select top 1st row's id etc..
any help will be appreciated Thanks !