By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

How to recall the last 5 rows from a table?

P: n/a
Hello!

I need some help.

How can I recall the last 5 rows from a MySQL table and show them?

Where is the FAQs of this newsgroup?
Sincerely,

Carlos
Jul 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 27 Aug 2003 12:15:41 -0700, ar****@hotmail.com (Carlos Marangon) wrote:
How can I recall the last 5 rows from a MySQL table and show them?


There is no such thing as the 'last 5 rows' in a database.

You need to use a field to order by. If you had a field created_dtm that was
the date and time that the row was inserted, then in MySQL it could be:

SELECT *
FROM yourtable
ORDER BY created_dtm DESC LIMIT 5

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #2

P: n/a
On 28 Aug 2003 21:12:42 -0700, ar****@hotmail.com (Carlos Marangon) wrote:
SELECT *
FROM yourtable
ORDER BY created_dtm DESC LIMIT 5


it is exactly my problem,
when I use this syntax it returns only 4 rows
and begin by the last but one.

I have in my table

for example

1 aaaaaaaaaaaaa
2 bbbbbbbbbbbb
3 cccccccccccc
4 ddddddddddddd
5 eeeeeeeeeeeee

It returns:

2 bbbbbbbbbbbb
3 cccccccccccc
4 ddddddddddddd
5 eeeeeeeeeeeee

How can I make it returns
1 aaaaaaaaaaaaa
2 bbbbbbbbbbbb
3 cccccccccccc
4 ddddddddddddd
5 eeeeeeeeeeeee


Post some code. You're probably missing a row somewhere, by fetching one more
time than you're printing.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #3

P: n/a

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:ut********************************@4ax.com...
Post some code. You're probably missing a row somewhere, by fetching one more time than you're printing.


My bet is he's counting from 1 to 5 rather than from 0 to 4.
--- Hacksaw
Jul 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.