Fetching a certain # of items from MySQL [Resolved]
Is it possible to do a mySQL query that returns like, say, the 10 more recent results? Or purphaps the 10 highest IDs in a database but can also account for the possibility there may be only 3 or 8?
Basically I need an easy way to grab the 10 most recent items from a database but also there may not be more than 3 or 8 but there could also be 15.
What do you recommend?
Re: Fetching a certain # of items from MySQL
I don't understand this one much. :( hmmm.
is this more of a database problem? like making the query?
well i think it can be done programatically, u just order the records the most recent goes on top.. and do some fancy codework. :)
Re: Fetching a certain # of items from MySQL
Yeah it's a database thing.
I know how to fetch everything and then basically break it apart, however; I thought I saw some MySQL LIMIT queries online, I just can't get them to work or figure out how to use them. I figured if I could limit the amount of items returned from a MySQL query, it would be more efficient.
Re: Fetching a certain # of items from MySQL
You need to sort your results in descending order then apply the LIMIT, like this.
Code:
SELECT column_1, column_2 FROM table_1 WHERE condition ORDER BY column_to_sort DESC LIMIT 10
Re: Fetching a certain # of items from MySQL
Re: Fetching a certain # of items from MySQL [Resolved]
You will need to add a new column with a timestamp. As there is no gurauntee you will get the records out in the same order it went in.