Skip to content
Advertisement

Tuning a query converting subquery

I was trying to change an update statement where there is a subquery in the WHERE clause to a join in order to improve performance. DDL to sample table/data

The query that uses a subquery:

My attempt of converting it to JOIN

However, this displays nothing while I expect two rows; and it is happening because of b.rn <> 1 I expected it would display the NULL values when it is b.rn <> 1

Any explanation for this? Any guide on better approach of tuning the query is much appreciated.

Thanks.

Advertisement

Answer

You can just move the subquery to the FROM clause and use LEFT JOIN:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement