tags:

views:

62

answers:

5

consider a tale is as follows,

EmployeeId | Name | Phone_Number

Now, i insert 10 records... When i query them back, select * from myTable they are not selected in the order i inserted. I can obviously keep an autoincrement index and ORDER BY index. But i dont want to alter the table. How can i do this without altering the table?

+1  A: 

Unfortunately there is no way to do this.

Anthony Faull
+1  A: 

Without an ORDER BY clause, there is no guaranteed order for the data to be returned in.

You would need to order by a column that indicates the inserted order, such as an IDENTITY field or a "Creation Date" field.

AdaTheDev
+1  A: 

Any ordering of result must be done using ORDER BY, if you don't use it the result will be returned in an undetermined order.

codaddict
A: 

There is no standard way to do this without adding an additional date, autoincrement index or some other counter to your table. Depending on your database there are some hacks you could do with SQL triggers to track this info in a separate table, but I suspect you don't want to do that (not all databases support them and they are not generally portable).

Dean Povey
+1  A: 

Isn't "EmployeeId" an auto-increment field? If it is, you can order by it to get data in order in which you inserted it.

binaryLV