This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes inserting data in mysql in sorting order of date column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "inserting data in mysql in sorting order of date column" Watch "inserting data in mysql in sorting order of date column" New topic
Author

inserting data in mysql in sorting order of date column

sandy sean
Ranch Hand

Joined: Dec 30, 2010
Posts: 69
Hi!

I want to store some records in mysql database. records have a date column. i want to store them in sorting order of that date column.

For example, record having date 27/sep/2011 get stored as first row on the top of record having date 26/sep/2011 as:

id_1,name_1,27/sep/2011
id_2,name_2,26/sep/2011

if new records come on future dates they would get inserted on the top.

I DONT want to order them while using select by using order by desc . i want they get inserted into db directly in sorted order.

how to do this???

thanks...
Zandis Murāns
Ranch Hand

Joined: Aug 18, 2009
Posts: 174

Absolutely impossible.
sandy sean
Ranch Hand

Joined: Dec 30, 2010
Posts: 69
Actually what i want to do is described as follows:

I am implementing pagination using Sql limit in mysql db.Records are needed to get

retrieved from the last row backwards. There are several thousands records in table

and i want to retrieve say 500 records at a time to show up in a page.


"select * from tbl_name order by some_col desc" will retrieve all records. but i

do not want all records, as they are thousands in number.


If i use "select * from tbl_name order by some_col desc limit 500" it will return

last 500 records in descending order.


but i could not find a way to retrieve next block of 500 in reverse direction,

starting from a point where first block have left up.


Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

What you need is a "pagination query". How such query is constructed depend on the database you are using. I'd suggest to search for mysql pagination query on this site or the web in general, there are countless examples and explanations.
 
 
subject: inserting data in mysql in sorting order of date column
 
Similar Threads
Comparing Dates
Determining how many records have same field
Help!!! Insert a new record with a field whose value based on existing records
Sorting Strings in Oracle
Dates in MySQL