* 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]