Re: last

From: Roji. P. Thomas (lazydragon_at_nowhere.com)
Date: 09/05/04


Date: Sun, 5 Sep 2004 12:21:38 +0530


>SELECT MAX(userid)
>FROM Users
>WHERE UserDate = (SELECT MAX(UserDate) FROM Users)

Its just same as

SELECT MAX(userid)
FROM Users

Comparing with the max of a Non-Unique column might return more than
one records. So you have to use an aggregate function in the select list
also.

And even then it doesnt guarantee the behaviour of First or Last

-- 
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Dan Guzman" <guzmanda@nospam-online.sbcglobal.net> wrote in message
news:OxHTZBpkEHA.3712@TK2MSFTNGP15.phx.gbl...
> I suspect Savas is expecting the behavior of the LAST aggregate function
in
> Access.  LAST will return data from the most recently inserted row.
> Conversely, FIRST will return data from the oldest row.  These are not
> relational and are not implemented in SQL Server.
>
> MAX can be substituted in many cases, depending on the business
> requirements.  If the desired value is indeed based on chronology, a
> datetime column or other incremental value is needed to identify the
> required value.  A query like the following can then be used.
>
> SELECT MAX(userid)
> FROM Users
> WHERE UserDate = (SELECT MAX(UserDate) FROM Users)
>
> -- 
> Hope this helps.
>
> Dan Guzman
> SQL Server MVP
>
> "David Portas" <REMOVE_BEFORE_REPLYING_dportas@acm.org> wrote in message
> news:euLOCblkEHA.3968@TK2MSFTNGP11.phx.gbl...
> > Maybe what you want is:
> >
> > SELECT MAX(userid)
> >    FROM Users
> >
> > A table in SQL has no inherent order so there is no concept of a "last"
> > row. If you want something other than the MAX then you'll have to
explain
> > what you mean by "last".
> >
> > -- 
> > David Portas
> > SQL Server MVP
> > --
> >
> >
>
>


Relevant Pages