Roger:

Thank you for your kind answer.

In respect to  SHOW TABLE STATUS LIKE "tablename"

Seemingly it doesn't work.

The sintax  SHOW TABLE STATUS FROM dbName

Work fine, but it works at database level (can present access problems).
Also must obtain the result for ALL the tables in the database (it is not
direct).

In respect to ORDER BY ... DESC combined with LIMIT 1:

I´v arrived to this other for my own (thank you anyway), but I suspect that
maybe it is not very efficient from the computation point of view (I suppose
it must travel the whole table to discard the undesired results).

LAST_INSERT_ID() function:

This other one has proven before, but in my case it returns many results (in
fact, the last one es the desired data).

"The most direct way is to SELECT the MAX() value from the table:"

OK You are right!!.   In my opinion it is not only the "most direct", but
the ONLY direct .  I admit that I had not understood the meaning of  this
sentence :-(

Thank you again!!

A.J.Millan.

""Roger Baklund"" <[EMAIL PROTECTED]> escribió en el mensaje
news:[EMAIL PROTECTED]
> * A.J.Millan
> > Supposing that fieldName is the a primary numeric auto-increment Key
field
> > in a table.
> > Does exist some direct method to find the biggest fieldName value
actually
> > stored? (without scan across all the table)
>
> There are several ways to do this, which way to use depends on the
> situation.
>
> The most direct way is to SELECT the MAX() value from the table:
>
> SELECT MAX(fieldName) FROM tablename
>
> You could also use ORDER BY ... DESC combined with LIMIT 1:
>
> SELECT fieldName FROM tablename ORDER BY fieldName DESC LIMIT 1
>
> In some cases you can also use the ouput from SHOW TABLE STATUS. It has a
> column named Auto_increment, this column contains the _next_ value for
this
> column, if there has been no DELETEs the current highest number will be
one
> smaller than the number returned.
>
> SHOW TABLE STATUS LIKE "tablename"
>
> If you have just INSERTed a row using the same connection, and this is the
> row for wich you want to know the auto_increment value, you should use the
> LAST_INSERT_ID() function. It will contain the last inserted
auto_increment
> id for _this_ connection, in a multi-user environment this is normally
what
> you want.
>
> <URL: http://www.mysql.com/doc/en/Information_functions.html#IDX1403 >
>
> --
> Roger
>



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to