Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep Max value from a unqiue fields 1

Status
Not open for further replies.

acjordan

Technical User
Feb 27, 2007
2
US
Basicly this is the problem.
I have one value that can have multiples and have a quanity attached to it. I want to return that value once and get the highest quanity. (ie. NAME, ORDER QUANITY - Joe 5, Joe 15 Joe 12 it would return Joe 15)

Thanks
For your help!
 
Perhaps did you need something else in your record, such as an ORDER_ID for example.
Try this :
Code:
select	A.NAME
	,	A.ORDER_ID
	,	A.ORDER_QTY
from	MyTable	as A
where	exists (	select	1
					from	MyTable as B
					where	A.NAME = B.NAME
					having	A.ORDER_QTY = max(B.ORDER_QTY)
				)
;
 
Thanks thats just what I need I don't know why I didn't think of it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top