RE: Select Highest ID query

2001-09-07 Thread Johnny Withers

Why not just:

SELECT MAX(id) AS max_id FROM yourtable;

Then run another select to get the record?

Or, if you want the last record:

SELECT * FROM yourtable ORDER BY id DESC LIMIT 1;

maybe.

-
Johnny Withers
[EMAIL PROTECTED]
p. 601.853.0211
c. 601.209.4985 

-Original Message-
From: Ian Moore [mailto:[EMAIL PROTECTED]] 
Sent: Friday, September 07, 2001 9:28 AM
To: Chris Bolt
Cc: [EMAIL PROTECTED]
Subject: Re: Select Highest ID query


On Thu, Sep 06, at 11:05pm, Chris Bolt ([EMAIL PROTECTED]) wrote:

> SELECT * FROM yourtable WHERE id = LAST_INSERT_ID();

But that will only work if it was the same thread that inserted the last
record in the table. If this is running from say .. a script that just
wants the last inserted record (highest ID) then it will not work
because LAST_INSERT_ID() will return 0.

-- Ian


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail
<[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: Select Highest ID query

2001-09-07 Thread Ian Moore

On Thu, Sep 06, at 11:05pm, Chris Bolt ([EMAIL PROTECTED]) wrote:

> SELECT * FROM yourtable WHERE id = LAST_INSERT_ID();

But that will only work if it was the same thread that inserted the last record in
the table. If this is running from say .. a script that just wants the last
inserted record (highest ID) then it will not work because LAST_INSERT_ID()
will return 0.

-- Ian


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: Select Highest ID query

2001-09-06 Thread Chris Bolt

> Im managing to do this, but I can see that the method im using is
> not as efficient as it could be. What I want to do is this
> Make a query which will grab the record in a table that has the
> highest ID number. The ID field is auto incremental so what its
> saying is that the record with the highest ID field is the newest
> record.
> 
> Any suggestions on how I can do this efficiently ?

SELECT * FROM yourtable WHERE id = LAST_INSERT_ID();

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: Select Highest ID query

2001-09-06 Thread Ian Moore

This is what I use in those situations:

select * from TABLE_NAME order by ID desc limit 1;

On Fri, Sep 07, at 01:43pm, Chris Aitken ([EMAIL PROTECTED]) wrote:

> Hi all,
> 
> Just quickly,
> 
> Im managing to do this, but I can see that the method im using is not as 
> efficient as it could be. What I want to do is this Make a query which 
> will grab the record in a table that has the highest ID number. The ID 
> field is auto incremental so what its saying is that the record with the 
> highest ID field is the newest record.
> 
> Any suggestions on how I can do this efficiently ?
> 
> 
> 
> Thanks
> 
> 
> Chris
> 
> 
> --
>  Chris Aitken - Administration/Database Designer - IDEAL Internet
>   email: [EMAIL PROTECTED]  phone: +61 2 4628   fax: +61 2 4628 8890
>   __-__
>*** Big Brother ***
> It just shows that the dull will rule the world. And we will be watching it.
> 
> 
> -
> Before posting, please check:
>http://www.mysql.com/manual.php   (the manual)
>http://lists.mysql.com/   (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Select Highest ID query

2001-09-06 Thread Chris Aitken

Hi all,

Just quickly,

Im managing to do this, but I can see that the method im using is not as 
efficient as it could be. What I want to do is this Make a query which 
will grab the record in a table that has the highest ID number. The ID 
field is auto incremental so what its saying is that the record with the 
highest ID field is the newest record.

Any suggestions on how I can do this efficiently ?



Thanks


Chris


--
 Chris Aitken - Administration/Database Designer - IDEAL Internet
  email: [EMAIL PROTECTED]  phone: +61 2 4628   fax: +61 2 4628 8890
  __-__
   *** Big Brother ***
It just shows that the dull will rule the world. And we will be watching it.


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php