> the LAST record entered in the database.... if for example if you
> entered 10 records in a new database, how do you fetch #10 - or the LAST
> recorded
> entered (without indicating 'get the 10th record')
Again, SQL Server doesn't keep track of which row is the newest. This is
not Access, and you are not stuffing a line of data at the end of a text
file.
What does your table structure look like Do you have a naturally
increasing column (such as IDENTITY, or DATETIME reflecting when the row was
created)
A
What does "last" mean A table is an unordered set of rows, so you need to
indicate to SQL Server what you mean by "last"...
wrote in message
news:c6e41dc5-463e-4bfd-b88c-99ebbc38e746@discussions.microsoft.com...
> Don't know if this is the right SQL section, but... using VBE, how do
> you SQL for the last record in the database
>
> Thanks.
>
the LAST record entered in the database.... if for example if you entered 10 records in a new database, how do you fetch #10 - or the LAST recorded entered (without indicating 'get the 10th record')
Your reply has helped me a lot !!!! I have been searching for this answer since a long time and didn't get any answer from any where !!!!I am extremely thankful to you.
> the LAST record entered in the database.... if for example if you
> entered 10 records in a new database, how do you fetch #10 - or the LAST
> recorded
> entered (without indicating 'get the 10th record')
Again, SQL Server doesn't keep track of which row is the newest. This is
not Access, and you are not stuffing a line of data at the end of a text
file.
What does your table structure look like Do you have a naturally
increasing column (such as IDENTITY, or DATETIME reflecting when the row was
created)
A
I'd recommend using the IDENT_CURRENT function. However it is limited to one table. So if you're looking for the last entered id across all tables...well it's a bit more complex. Unless you use some kind of scheme that identifies what table an ID belongs too. I've seen this used at companies where they have a single generator for all IDs. But I digress.
Select * from table_name where id=IDENT_CURRENT('table_name')
Get last record in a SQL database
Hector Y. Martinez
able to open the database... so I'm reading a book.
shauli
SELECT MAX id but wasn't sure if there was a better way of doing so.
Gaurav Jain
isn't is what you're asking for
Shinji
Daniel Baum
Haydee
vindos
AHachmann
SELECT *
FROM TABLE
WHERE ID = IDENT_CURRENT('TABLE')
or
SELECT *
FROM TABLE
WHERE ID = (SELECT MAX(ID) FROM TABLE)
I hope this helps.
Sincerely,
Edward E. Weller
Keehan
entered (without indicating 'get the 10th record')
pext
Dear Valeriy,
Your reply has helped me a lot !!!! I have been searching for this answer since a long time and didn't get any answer from any where !!!!I am extremely thankful to you.
May God Bless you always
Thanks
Maleeha
darrellp
kaufman
I'd recommend using the IDENT_CURRENT function. However it is limited to one table. So if you're looking for the last entered id across all tables...well it's a bit more complex. Unless you use some kind of scheme that identifies what table an ID belongs too. I've seen this used at companies where they have a single generator for all IDs. But I digress.
Select * from table_name where id=IDENT_CURRENT('table_name')
Should do what you want.
johnconstantine
Skyline58687
athanks to all fo royu help I got it