Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to show only the last 4 records of database

Status
Not open for further replies.

MarioVITAL

IS-IT--Management
Joined
Apr 4, 2003
Messages
3
Location
PT
i trying to show the last itens i insert into the table ... but without sucess.. can someone help me

thz in advanced
 
It depends on how your table is defined. In general a concept such as last is void of meaning in a relational database. You cannot assume that records in a table is stored in the same order as they are entered. For this to work you must have a columns that reflects the order in which data was entered, i.e. a datetime or auto_increment column.

select * from t order by c limit 4
 
to add on to swampBoogie:

Code:
select * from t order by c DESC limit 4
                             ^

depending on the value of c (but I am assuming if its an auto-increment or a timestamp, it will always be biggest at the "end") you want to order your result set to descend from greatest to least, and give you the 4 "greatest".
 
running on a large oracle dbase with different user applications pulling data fom it. Got stuck on what i thought was a simple issue.

Anyone know how to limt the record set fetched back through a SQL command to the last 10. The records are not in sequence via the auto-increment table key and are selected via a criteria placed against one of the other fields.

I had a go with select top 10 but get the first 10 records of the type requested!!!

Mike
 
I am using SQL in the application to get the data
 
oracle's sql is not the same as mysql's sql

and neither of them is standard sql

i think you'd be better off in the long run posting oracle questions in an oracle forum



r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top