views:

218

answers:

2

can we always convert a usual subquery/correlated subquery to join type query?

+1  A: 

Yes, but it means that what you JOIN to can appear in the result set. A subquery in either an EXISTS or IN clause would not have this risk.

OMG Ponies
You can also add correlated subqueries in the SELECT clause.
Thomas
A: 

yes and no...

  • Yes, in that JOIN/EXISTS/IN usually give the same plan and are often the same

  • No, in that if the EXISTS table has > 1 row for the main table you'll need DISTINCT to avoid dupes

I'd stick with an EXISTS type query if this is relevant and you don't need data from the EXISTS table

gbn