473,388 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to recall the last 5 rows from a table?

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
3 5842
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Daniel Ng | last post by:
Thanks for the 2 guys how hep to to solve to count the number of recount in forum. I'm done wif that. Got 1 more question.. Example Record 1: ID 2 VALUE 2 Record 2: ID 3 VALUE 3 Record 3: ID 2...
4
by: Stefan Mueller | last post by:
I have a table dynamically created with a JavaScript (insertRow, deleteRow). At the end I'd like to go through the whole table (beginning at the first and ending at the last row) to display all the...
20
by: Guru | last post by:
Hi I have a table which contains number of rows. I want to fetch the last 5 records from the table. I know for the first 'n' records we can use FETCH FIRST n ROWS ONLY command. But i want to...
0
by: bunty.gopal | last post by:
I am trying to use the PreparedStatement's addBatch to load data in an ETL-like process into a table. There is a single prepared statement. The parameters are set on it and prepStmt.addBatch() is...
5
by: JonH | last post by:
Ok, I have this dynamically created table in my one of my php forms that shows the names of the people the user has entered into a text field. When they hit add a row displays, showing the name...
2
by: Luis P. Mendes | last post by:
Hi, I would like to know if there is a better way to do what I'm already doing as stated in the following example, when using psycopg2 with PostgresQL. ........................ nr_bars_before =...
1
by: bunty.gopal | last post by:
This is the solution to the issue in the subject, question itself was posted in a previous thread long back. Use the latest DB2 db2cc.jar fixpack on the client, or add "deferPrepares=false" to...
0
by: marlberg | last post by:
Platform: Windows2000, WindowsXP, Windows Vista, etc Language: C#, ASP.NET Pre-compiled Libraries: Enterprise Library 3.0 full I have a requirement to implement in and display in C# and...
3
chathura86
by: chathura86 | last post by:
hi i want to get the last row of a table but this table has another table in each cell so var rows = table.getElementsByTagName('tr'); var lastrow = rows;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.