I have a sample query
select
x as 1, y as 2 , z as 3
from
table abc, xyz
where
a = x and x = 123
Now I want to add two more columns in this SELECT statement like this:
- column 4 which will show the row sequence no.
- column 5: this column will depend on the row – it will show
startin first row,Lastin the last row andMiddlein any rows in between.
Please suggest the best possible optimize way to do this.
Thanks
Data doesn’t have an order unless you specify it.
Note the use of ANSI-92 joins instead of a where clause in the above query.
You may be able to optimise this further using a Common Table Expression
Or without a CTE like this: