Hi, How do I get the first and last row in a table? Is there a function available? (min ? max?...row_id) Not sure how to do it? Please help. Thank you.
Hi, How do I get the first and last row in a table? Is there a function available? (min ? max?...row_id) Not sure how to do it? Please help. Thank you.
Hi, How do I get the first and last row in a table? Is there a function available? (min ? max?...row_id) Not sure how to do it? Please help. Thank you.
use rownum=1 in where clause will get you the first and to get the last ???
there are ways to do..........Find it
Pascal01 needs the first row and the last row as inserted in the table. I know there is no first and last row concept in Oracle. He needs the way data are entered in the table first callled first data and the last as last data as it is available at a point in time. Guys test for yourself rownum works as i said:
Code:
SQL> create table san (i integer);
Table created.
SQL> insert into san values(1);
1 row created.
SQL> insert into san values(3);
1 row created.
SQL> insert into san values(5);
1 row created.
SQL> insert into san values(6);
1 row created.
SQL> commit;
Commit complete.
SQL> delete from san where i=1;
1 row deleted.
SQL> select * from san;
I
----------
3
5
6
SQL> select * from san where rownum=1;
I
----------
3
SQL> rollback;
Rollback complete.
SQL> select * from san where rownum=1;
I
----------
1
SQL> select * from san;
I
----------
1
3
5
6
SQL>
no, rownum is applied to the *result set* not the data in the table
so whatever row comes first from the table will be given rownum = 1, and the data will come out of the table in *ANY* order unless an order by is supplied - basic heap table concepts
Pascal01 needs the first row and the last row as inserted in the table. I know there is no first and last row concept in Oracle. He needs the way data are entered in the table first callled first data and the last as last data as it is available at a point in time. Guys test for yourself
Now try it on an index-organized table, or a cluster, or a partitioned table, or in a parallel query environment, or where there's an index on your column "I" (especially a descending index) ...
I'm with slim and davey on this, there is no first and last row.....there are just rows, its up to you how the data is used, you'd need something like a sequence or timestamp colum to order the rows in your SQL
Bookmarks