Jump to content
  • Advertisement
Sign in to follow this  

sql - how to get the first 10, or last 10...

This topic is 4753 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

playing with mysql db. How do I get the 10 last post in a table, or how to get the 10 last sorted after date? Anyway ... I know this place is maybe not the best regarding db and sql ... anybody who know of a better forum/site?

Share this post


Link to post
Share on other sites
Advertisement
If you're using MSSQL, use TOP:

SELECT TOP 10 * FROM table ORDER BY date DESC;

Sorry, I didn't see the bit about you using mysql.

Share this post


Link to post
Share on other sites
Use ORDER BY to get the table entries into the appropriate order, then use LIMIT to get the range of entries you want. You can use LIMIT X, Y where X is the offset into the recordset and Y is the number of entries you want returned. ORDER BY will be ascending by default, use ORDER BY [column] DESC to get them in descending order.

The mysql reference manual is the best first place to start. Just read up on the params that can be passed to the SELECT statement. ORDER BY and LIMIT are fairly basic params. google search "mysql forums" should give you a good list of forums specifically for mysql (I don't know if links to other dev oriented forums are allowed).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!