Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

My Table Is -

PurID - ProID - ProName - Quantity
1 - 3 - Mango - 10
2 - 3 - Mango - 20
3 - 3 - Mango - 30
4 - 6 - Banana - 15
5 - 6 - Banana - 25
6 - 6 - Banana - 35
7 - 8 - Orange - 100
8 - 8 - Orange - 200
9 - 8 - Orange - 300

I want to select PurID, ProID, ProName, Quantity of the maximum qunatity. Ex

PurID - ProID - ProName - Quantity
3 - 3 - Mango - 30
6 - 6 - Banana - 35
9 - 8 - Orange - 300

Is there any T-Sql squery to do that?
Posted
Comments
Kornfeld Eliyahu Peter 23-Jun-14 5:33am    
There is. Any other question?
Raghubir_Sarkar 23-Jun-14 5:49am    
Please use the forum to solve problems of other programmers not to find out grammatical mistakes in question.
If you know the solution please help me to write the query.

1 solution

SQL
select PurID, ProID, ProName, MAX(Quantity) from MyTable GROUP BY ProID

should fit the job.
 
Share this answer
 
Comments
Raghubir_Sarkar 23-Jun-14 10:20am    
Thank you
It throws Following error -
"You tried to execute a query that does not include the specified expression 'PurID' as part of an aggregate function"

If i remove PurID then same error occur for ProName. Only Following query runs -

Select ProID, Max(Quantity) from MyTable Group BY ProID

But I want PurID also, it is primary key.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900