Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract the highest auto_increment numbered record

Status
Not open for further replies.

geroid

IS-IT--Management
Apr 9, 2009
9
IE
Hi
Can anyone help me to formulate this SQL query. I have a table with an auto_incremented field whenever a record is inserted. What I want to do is throw a record back at the user after it is inserted as a confirmation. Now I know that the said record must be the one with the highest number as it has just been inserted. So what I need to do is scan my table for the record with the highest (the field is called eventnum) number. I can pretty much write the select query myself but what is the code to just extract that one record with the highest eventnum number?

This is the code I'm currently using but I realised that this could bring up several records with the same venuename. I just what the latest record that was inserted based on the hifhest eventnum number.
Code:
<?
$query = "select event_num, event_name, venue_name, streetaddress1, town, county, event_description, date_format(event_date, '%M %D, %Y ') as formatteddate, event_time from $table where venue_name = '".$_SESSION['venuename']."'";

?>
 
don't do it that way, use the LAST_INSERT_ID function instead

by the way, you should post your questions in forum436 instead

:)

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top