Re: insert/select question "K.Fawcett" <k.fawcett@mccsoftware.com> wrote in message
news:1113582283.535020.65910@l41g2000cwc.googlegro ups.com...
>I am doing a simple insert into a table and I would like the data to be
> retrieved in the order it is inserted not by what appears to be
> alphabetical order.
>
> insert into mytbl values('c')
> insert into mytbl values('b')
> insert into mytbl values('a')
>
> select * from mytbl yields
>
> a
> b
> c
>
> I would like the select to yield
> c
> b
> a
> (the order in which the data was inserted)
>
> What is db2 doing with the ordering during insert?
>
The only way would be to define a timestamp column on the table and let DB2
default to the "current timestamp" when the data is inserted. Then you could
use the ORDER BY clause to retrieve the rows by the timestamp column.
By definition, a relational database does not guarantee the rows will be
returned in any particular order unless you specify the order with ORDER BY. |