Re: MAX function

From: Adam Machanic (amachanic_at_hotmail._removetoemail_.com)
Date: 01/12/05


Date: Wed, 12 Jan 2005 11:51:40 -0500


"Hugo Kornelis" <hugo@pe_NO_rFact.in_SPAM_fo> wrote in message
news:54o9u0plrjarugr2ma6c4lht2ojrbvol8o@4ax.com...
>
> Using standard SQL:
>
> SELECT title_id
> FROM titles
> WHERE ytd_sales = (SELECT MAX(ytd_sales)
> FROM titles)
>
> Using the proprietary TOP keyword:
>
> SELECT TOP 1 title_id
> FROM titles
> ORDER BY ytd_sales DESC

    For symmetry, you'd probably want the second query to be:

SELECT TOP 1 WITH TIES title_id
FROM titles
ORDER BY ytd_sales DESC

-- 
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--


Relevant Pages