开发者

Selecting X oldest date from the database

开发者 https://www.devze.com 2023-03-22 00:39 出处:网络
Good Afternoon Please can someone hel开发者_开发技巧p me, I’m nearly a total noob.I have a very simple DB which has thousands of rows and very few columns.I have an ID, Name, Image, Information, an

Good Afternoon

Please can someone hel开发者_开发技巧p me, I’m nearly a total noob. I have a very simple DB which has thousands of rows and very few columns. I have an ID, Name, Image, Information, and Date Added. Really basic!

Now I’m trying to display only a single row of data at a time so there is no need for loops and things in this request. Sounds very simple in theory?.

I can display a row in date order, and by the most recent or oldest, ascending or descending. But I want to be able to display for example: = The 6th newest entry. And perhaps somewhere else on my sites the 16 most recent entry and so on. This could even be the 1232 most recent entry.

Sounds to me like it would be a common task but I can’t find the answer anywhere. Can someone provide me with the very short command for doing this? I probably missing something really daft and fundamental.

Thanks

Leah


The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants (except when using prepared statements).

With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):

SELECT * FROM tbl LIMIT 5,10;  # Retrieve rows 6-15

http://dev.mysql.com/doc/refman/5.1/en/select.html

So if you want the 1232nd row from your table you can something like this:

SELECT * FROM tbl ORDER BY date_added LIMIT 1231,1;


In your query use LIMIT e.g.

LIMIT 6,1 // Starts at row 6 and retrieves one result.

0

精彩评论

暂无评论...
验证码 换一张
取 消