I have a query that does a self join following by correlated subquery. I want to be able to select from "this row" or the latest row before "this row", based on the "rn" column, where column1 is populated. Its currently working using a correlated subquery as follows:
Its a bit slow though since its needs to execute the inner query for each row in the outer query. I have seen examples of converting this to a join but cant seem to get it to work, as I always need to reference the outer query for
part.
Can anyone help converting this to a non-correlated query?
thanks
Code:
select a.id, coalesce(a.typeName, b.typeName) as typeName FROM table1 a, table1 b where a.id = b.id AND b.rn = ( select max(rn) from table1 where id = a.id and rn <= a.rn and column1 is not null )
Code:
rn <= a.rn
Can anyone help converting this to a non-correlated query?
thanks
Comment