Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving data from table in the order of insertion

 
Shashank Anand
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34681
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic