Re: MAX function
From: Adam Machanic (amachanic_at_hotmail._removetoemail_.com)
Date: 01/12/05
- Next message: Alejandro Mesa: "Re: Procedure or function XXX has too many arguments specified???"
- Previous message: Anith Sen: "Re: Extracting index's as script"
- In reply to: Hugo Kornelis: "Re: MAX function"
- Messages sorted by: [ date ] [ thread ]
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 --
- Next message: Alejandro Mesa: "Re: Procedure or function XXX has too many arguments specified???"
- Previous message: Anith Sen: "Re: Extracting index's as script"
- In reply to: Hugo Kornelis: "Re: MAX function"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|