Lyleyboy Posted July 5, 2008 Share Posted July 5, 2008 Hi all, I am in need of two queries from the same table. I have an ID which is an auto incremented number. There will be some gaps in the ID range. Query 1, I want to pull the record with the highest ID i.e. I have records 1,3,4,6,7,9,11,15,18,20,23 I only want to pull ID 23 Query 2, I want to pull the next five records i.e. 23,20,18,15 and 11 I hope this makes sense to someone. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/113374-solved-select-top-1-and-top-2-6-records-from-mysql/ Share on other sites More sharing options...
wildteen88 Posted July 5, 2008 Share Posted July 5, 2008 SELECT * FROM your_table ORDER BY your_id_column DESC LIMIT 5 that will return rows 23, 20, 18, 15 and 11 Link to comment https://forums.phpfreaks.com/topic/113374-solved-select-top-1-and-top-2-6-records-from-mysql/#findComment-582470 Share on other sites More sharing options...
DarkWater Posted July 5, 2008 Share Posted July 5, 2008 SELECT * FROM yourtable ORDER BY id DESC LIMIT 5 Link to comment https://forums.phpfreaks.com/topic/113374-solved-select-top-1-and-top-2-6-records-from-mysql/#findComment-582471 Share on other sites More sharing options...
Lyleyboy Posted July 5, 2008 Author Share Posted July 5, 2008 Superb. I knew there would be an easy way. I was off doing logic checks and using an incremented counter. Link to comment https://forums.phpfreaks.com/topic/113374-solved-select-top-1-and-top-2-6-records-from-mysql/#findComment-582503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.