Hi,
Does somebody knows an alternative for the function last() in access. I've a
lot queries which uses last, but there is no alternative in sql server.
I used min/max but that did not gave me the right results. I need to know
the last row in a 1-to-many table situation.
Is there something like a hidden rowid i can use?Jason
See MAX(),MIN() funtions in the BOL.
\
"Jason" <jasonlewis@.hotrmail.com> wrote in message
news:OXIlbqZGFHA.3648@.TK2MSFTNGP09.phx.gbl...
> Hi,
> Does somebody knows an alternative for the function last() in access. I've
a
> lot queries which uses last, but there is no alternative in sql server.
> I used min/max but that did not gave me the right results. I need to know
> the last row in a 1-to-many table situation.
> Is there something like a hidden rowid i can use?
>|||Select top 1 * from table order by field desc
Madhivanan|||There is NO exact equivalent of the LAST function of Access in SQL server.
This is based on the relational concept that the rows in a table are not
ordered.
So anything like LAST, FIRST, NEXT etc are totally meaningless.
If you have a column that records data in any chronological order, you can
achieve the same by using the MAX function.
> Is there something like a hidden rowid I can use?
No, there is nothing like that exposed.
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Jason" <jasonlewis@.hotrmail.com> wrote in message
news:OXIlbqZGFHA.3648@.TK2MSFTNGP09.phx.gbl...
> Hi,
> Does somebody knows an alternative for the function last() in access. I've
> a
> lot queries which uses last, but there is no alternative in sql server.
> I used min/max but that did not gave me the right results. I need to know
> the last row in a 1-to-many table situation.
> Is there something like a hidden rowid i can use?
>|||HI Mad,
How is sytax if i want it to join with another table (the 1 side of
1-to-many)?
<madhivanan2001@.gmail.com> wrote in message
news:1109158964.898453.171390@.f14g2000cwb.googlegroups.com...
> Select top 1 * from table order by field desc
> Madhivanan
>|||If you have the concept of last, then there is some ordering.... If for
example you want the last price ( with the ordering being the title_id),
then sort the rows in the reverse order, so the last row becomes the first
row returned, and select the top 1... ie
select top 1 price from titles order by title_id desc
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Jason" <jasonlewis@.hotrmail.com> wrote in message
news:OXIlbqZGFHA.3648@.TK2MSFTNGP09.phx.gbl...
> Hi,
> Does somebody knows an alternative for the function last() in access. I've
> a
> lot queries which uses last, but there is no alternative in sql server.
> I used min/max but that did not gave me the right results. I need to know
> the last row in a 1-to-many table situation.
> Is there something like a hidden rowid i can use?
>|||Please post DDL and sample data so that we don't have to guess what
your table structure looks like:
http://www.aspfaq.com/etiquette.asp?id=5006
You'll aslo have to tell us what you mean by the "last row" there is no
fixed concept of first and last in a table because tables in SQL have
no inherent logical order.
David Portas
SQL Server MVP
--