显示标签为“course”的博文。显示所有博文
显示标签为“course”的博文。显示所有博文

2012年3月7日星期三

First() and last() function -> course says yes, Book on line says no

Richard,

> Could they make that big a mistake?
Apparently so :-)
Chief Tenaya
"Richard Fagen" <no_spam@.my_isp.com> wrote in message
news:eGRLEejHEHA.3464@.TK2MSFTNGP10.phx.gbl...
> Hi Everyone,
> I'm taking an online course to learn more about SQL. I found this great
> site...
> http://www.w3schools.com/sql/default.asp
> In one of the lessons, it mentions SQL server's functions. However,
> when I tried it, it doesn't work. I checked the Books online and it
> appears there is no such function. Could they make that big a mistake?
> I know there are other ways of doing the same thing but I found the site
> very accurate and this surprises me.
> Here is the page in question. The problems: it claims there is a First
> (and Last) function...
> http://www.w3schools.com/sql/func_first.asp
> -- here is their example
> "The FIRST function returns the value of the first record in the
> specified field.
> Tip: Use the ORDER BY clause to order the records!
> Syntax
> SELECT FIRST(column) AS [expression]
> FROM table
> Example
> SELECT FIRST(Age) AS lowest_age
> FROM Persons
> ORDER BY Age"
You need the TOP modifier. eg.
SELECT TOP 1 Age AS lowest_age
FROM Persons
ORDER BY Age
HTH,
Greg Low (MVP)
MSDE Manager SQL Tools
www.whitebearconsulting.com
"Richard Fagen" <no_spam@.my_isp.com> wrote in message
news:eGRLEejHEHA.3464@.TK2MSFTNGP10.phx.gbl...
> Hi Everyone,
> I'm taking an online course to learn more about SQL. I found this great
> site...
> http://www.w3schools.com/sql/default.asp
> In one of the lessons, it mentions SQL server's functions. However,
> when I tried it, it doesn't work. I checked the Books online and it
> appears there is no such function. Could they make that big a mistake?
> I know there are other ways of doing the same thing but I found the site
> very accurate and this surprises me.
> Here is the page in question. The problems: it claims there is a First
> (and Last) function...
> http://www.w3schools.com/sql/func_first.asp
> -- here is their example
> "The FIRST function returns the value of the first record in the
> specified field.
> Tip: Use the ORDER BY clause to order the records!
> Syntax
> SELECT FIRST(column) AS [expression]
> FROM table
> Example
> SELECT FIRST(Age) AS lowest_age
> FROM Persons
> ORDER BY Age"

First() and last() function -> course says yes, Book on line

Hi,
I guess that's what they meant by each flavour of SQL can have slightly
different syntax and to check with the manuals.
Thanks for confirming it.
Richard
Tenaya wrote:
> Richard,
>
>
> Apparently so :-)
> Chief Tenaya
Hi Greg,
This sounds like it should work. I checked Book Online but can't find
any mention of the top modifier ... aside from inside the complicated
full explaination of the SELECT statement. Is this what you meant?
I never realized who powerful (and complicated) the SELECT statement is
Thanks for your help
Richard
From Books Online's select (described)
...
< query specification > ::=
SELECT [ ALL | DISTINCT ]
[ { TOP integer | TOP integer PERCENT } [ WITH TIES ] ]
< select_list >
[ INTO new_table ]
[ FROM { < table_source > } [ ,...n ] ]
[ WHERE < search_condition > ]
[ GROUP BY [ ALL ] group_by_expression [ ,...n ]
[ WITH { CUBE | ROLLUP } ]
]
[ HAVING < search_condition > ]
Greg Low (MVP) wrote:

> You need the TOP modifier. eg.
> SELECT TOP 1 Age AS lowest_age
> FROM Persons
> ORDER BY Age
> HTH,