aspose file tools*
The moose likes JDBC and the fly likes Retrieving data from table in the order of insertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Retrieving data from table in the order of insertion" Watch "Retrieving data from table in the order of insertion" New topic
Author

Retrieving data from table in the order of insertion

Shashank Anand
Greenhorn

Joined: Oct 30, 2008
Posts: 26
Hi,

I have a table with columns custname (VARCHAR(20) NOT NULL), orderno (INT NOT NULL). If I use SELECT * FROM table to retrieve data, the data is displayed in the ascending order of custname and then orderno. But I want the data to be displayed in the order of insertion into the table. Will anybody please tell me which query should I use to do this ?

Thanks,
Shashank.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30780
    
157

Shashank,
The database doesn't promise to store date in insertion order. The only way to obtain this info is to add a column representing the order (via a sequence) when you insert the data.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
Shasshank, is it possible your orderNo column is sequential and the record is inserted at the time the orderNo is assigned to the customer? If so you could do



If not, you have to do what Jeanne suggests (or something similar... like add a column that holds the datetime stamp for the rows creation).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Retrieving data from table in the order of insertion