Foser Posted January 31, 2008 Share Posted January 31, 2008 Basic question. I want to do something like this $info = mysql_query("SELECT topic_title, topic_first_poster_name, topic_id, forum_id, topic_poster FROM phpbb_topics WHERE ..."); I want WHERE topic_id is the highest number. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/88708-solved-mysql-query-where/ Share on other sites More sharing options...
nethnet Posted January 31, 2008 Share Posted January 31, 2008 <? $sql = "SELECT topic_title, topic_first_poster_name, topic_id, forum_id, topic_poster FROM phpbb_topics ORDER BY topic_id ASC LIMIT 1"; $info = mysql_query($sql) or die("Couldn't run the query."); ?> Quote Link to comment https://forums.phpfreaks.com/topic/88708-solved-mysql-query-where/#findComment-454253 Share on other sites More sharing options...
Foser Posted January 31, 2008 Author Share Posted January 31, 2008 I just want one ouput of the one with the biggest integer, not working.... Quote Link to comment https://forums.phpfreaks.com/topic/88708-solved-mysql-query-where/#findComment-454254 Share on other sites More sharing options...
nethnet Posted January 31, 2008 Share Posted January 31, 2008 "LIMIT 1" will return only one row from the database, and "ORDER BY topic_id DESC" will put all of the rows in reverse numerical order based on topic_id, so using them together will give you just one row, that being the highest topic_id... Quote Link to comment https://forums.phpfreaks.com/topic/88708-solved-mysql-query-where/#findComment-454258 Share on other sites More sharing options...
nethnet Posted January 31, 2008 Share Posted January 31, 2008 Just realized that in my first post I put ORDER BY topic_id ASC. The ASC should be DESC if you want the highest number. The other way will give you the lowest number. Quote Link to comment https://forums.phpfreaks.com/topic/88708-solved-mysql-query-where/#findComment-454260 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.