Jump to content

Archived

This topic is now archived and is closed to further replies.

Prismatic

Return highest field number from query?

Recommended Posts

Im having a big brain fart on this one  :P

I have a table setup like this

[quote]
[u]message_id | chat_id | user_id | user_name | message | post_time[/u]
233          |1          |10        |Bob          |Test        |2006-09-26 16:11:02
234          |1          |10        |Bob          |Weee      |2006-09-26 16:12:32
235          |1          |10        |Bob          |Arr!        |2006-09-26 16:14:56
etc..
[/quote]

What I need to do is run a query to grab the HIGHEST message_id in the table, anyone know what a query like that would look like? Sorry, im having a bad day heh

Thanks!


Share this post


Link to post
Share on other sites
Something like this should do it

$r = mysql_query("SELECT * FROM messages ORDER BY message_id DESC LIMIT 1") or die(mysql_error());


EDIT: Added limit

Share this post


Link to post
Share on other sites
Could even be simplified to:

[code=php:0]$sql = "SELECT max(message_id) FROM tablename";
[/code]

If you're just going to us an alias of exactly the same name, surely there's no point?

Regards
Huggie

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.