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!

PHP/Mysql Selecting latest addition to database

Status
Not open for further replies.

bobrivers2003

Technical User
Oct 28, 2005
96
GB
I have a mySQL table that includes requests with an auto increment id. The id's go from 0-n where n is the number of rows in the table. To select the lastest one I currently do a row count then "SELECT * FROM table WHERE id=$rowcount; to get the latest request.

This works fine if the id went from 0-n without missing any rows. e.g. for 1,3,4,5,10. The row count is 5 but instead of getting the latest request (id=10) it will pull request with id 5 not 10.

Is there a work around to this?
 
SELECT * FROM table WHERE id=(SELECT max(id) FROM table)

Should do it
 
try this:

SELECT * FROM table WHERE id order by id desc limit 0,1

Known is handfull, Unknown is worldfull
 
>>Bogiemon
SELECT * FROM table WHERE id=(SELECT max(id) FROM table)

hmm, that uses sub queries, carefull some versions of mySql do not support it...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top