Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sql return two max values
Message
 
 
To
08/09/2003 10:57:18
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00827089
Message ID:
00827124
Views:
19
Steve,

Try (untested)
SELECT vendor, invoice_date, invoice_amount
	FROM mytable mt
	JOIN (
		SELECT vendor, invoice_date, max(invoice_amount) AS invoice_amount
			FROM mytable mt1 ;
			WHERE invoice_date IN 
				(SELECT max(invoice_date) FROM mytabel mt2
					WHERE mt2.vendor = mt1.vendor)
GROUOP BY vendor, invoice_date
) dt1
		ON dt1.vendor = mt.vendor
			AND dt1.invoice_date = mt.invoice_date
			AND dt1.invoice_amount = mt.invoice_amount
     
>Hi:
>
>Unfortunately, this is no unique key in this table (not my design). I need to find the vendor with the lastest invoice date with the highest invoice amount.
>
>I hope this clears things up. Thanks for your help.
>
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform