View Full Version : get row with largest id num?

08-19-2006, 07:02 PM
i need to retrieve the first and last row of a table that has unique consecutive id numbers for each row

i can get the first with "where num = 0"

what about the last... keep in mind that i don't know how many entries there are.

i'd also like this to run quickly... so retrieving all sorted descending is a last resort

08-19-2006, 07:59 PM
select max(id) from table.

Good luck;

08-19-2006, 08:27 PM
what is it you are trying to do exactly? If you are trying to get that id to insert information in another row then look in the manual under last_insert_id() since you would want to use that instead in such a case.

I'm asking because a great number of people that are not familiar with using it don't know why using max(columnname) is.

of course if you just need to know the maximum of the column for another reason then using max(columname) is fine.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum