I have a table which looks like this.
NAME AGE
james 22
ames 12
messi 32
....
....
I can query this table using Select name, age from emp;
Now what I want is having an extra column before name which will be 1,2,3..N if the query return n rows.
SEQUENCE NAME AGE
1 james 22
2 ames 12
3 messi 32
4 ....
....
How I can do this?
if you want to just add a column which will contain sequence number at display time(not actually store that data in a table) you can use
ROWNUMpseudocolumn orrow_number()analytical function.The output of the above query is ordered by
NAMEbut you can order by any column or combination of columns you want.Second approach is using
rownumpseudocolumn. result is ordered bynamealso