Re: last

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Dan Guzman (guzmanda_at_nospam-online.sbcglobal.net)
Date: 09/04/04


Date: Sat, 4 Sep 2004 10:03:32 -0500

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