First and Last ID of a table

From: Date: Wed, 11 Jul 2007 20:06:03 +0000
Subject: First and Last ID of a table
Groups: php.db 
Request: Send a blank email to php-db+get-43769@lists.php.net to get a copy of this message
I have a table where I need to figure out the very first ID and the very last ID, so here is what I wrote: $first_query = "SELECT id FROM mytable ORDER BY id LIMIT 1"; $first_result = mysql_query($first_query,$con); $first_id = mysql_result($first_result,0,'id'); $last_query = "SELECT id FROM mytable ORDER BY id DESC LIMIT 1"; $last_result = mysql_query($last_query,$con); $last_id = mysql_result($last_result,0,'id'); I'm just wondering if there was any way to do this more efficiently, like with one query instead of two. Or is this about as simple as I can do it? Thanks. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326

« previous php.db (#43769) next »