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
Select top 1 and top 2-6 records from MySQL
Moderator: General Moderators
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Select top 1 and top 2-6 records from MySQL
Makes sense
Query 1
SELECT * FROM *TABLE* ORDER BY id DESC LIMIT 0,1
Query 2
SELECT * FROM *TABLE* ORDER BY id DESC LIMIT 0,5
Replace *TABLE* with the name of the table in your database
Query 1
SELECT * FROM *TABLE* ORDER BY id DESC LIMIT 0,1
Query 2
SELECT * FROM *TABLE* ORDER BY id DESC LIMIT 0,5
Replace *TABLE* with the name of the table in your database
Re: Select top 1 and top 2-6 records from MySQL
Superb thanks for that. I knew there would be an easy way

I'm not that daftjaoudestudios wrote:Replace *TABLE* with the name of the table in your database
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: Select top 1 and top 2-6 records from MySQL
Hehe, well that's good but some people are.I'm not that daft