hi all,
I was wondering if there is an easier way to find the (auto_increment)
id of the last row you entered than doing a select statement? At the
moment I use this line:
SELECT DISTINCT `sale_number` FROM `sales` ORDER BY `sale_number` DESC
LIMIT 1
to get the sale_number so that I can link other tables to the sale in
the same operation. it seems like a waste of database processing
though.
any advice would be greatly appreciated.Look up @.@.IDENTITY and it's use in BOL.
Nik Marshall-Blank MCSD/MCDBA
Linz, Austria
"Ben" <b.eppel@.gmail.com> wrote in message
news:1128512865.557869.305910@.z14g2000cwz.googlegroups.com...
> hi all,
> I was wondering if there is an easier way to find the (auto_increment)
> id of the last row you entered than doing a select statement? At the
> moment I use this line:
> SELECT DISTINCT `sale_number` FROM `sales` ORDER BY `sale_number` DESC
> LIMIT 1
> to get the sale_number so that I can link other tables to the sale in
> the same operation. it seems like a waste of database processing
> though.
> any advice would be greatly appreciated.
>|||Assuming you are using SQL Server 2000 you should use the
SCOPE_IDENTITY() function. Your suggested method wouldn't be reliable
in a multi-user system and LIMIT isn't a valid SQL Server keyword
anyway.
David Portas
SQL Server MVP
--|||I'm actually using mysql, I know that's not what this forum is for but
the people here are so clever.|||Clever we may be but we're not Psychic.
Nik Marshall-Blank MCSD/MCDBA
Linz, Austria
"Ben" <b.eppel@.gmail.com> wrote in message
news:1128514094.204595.138820@.f14g2000cwb.googlegroups.com...
> I'm actually using mysql, I know that's not what this forum is for but
> the people here are so clever.
>|||mysql_insert_id()
http://dev.mysql.com/doc/mysql/en/mysql-insert-id.html
I found this using Google. Very clever of me :-)
--
Nik Marshall-Blank MCSD/MCDBA
Linz, Austria
"Ben" <b.eppel@.gmail.com> wrote in message
news:1128514094.204595.138820@.f14g2000cwb.googlegroups.com...
> I'm actually using mysql, I know that's not what this forum is for but
> the people here are so clever.
>
No comments:
Post a Comment