Please can anyone give me the difference between using a Correlated sub-query over a JOIN ? Are they not meant to solve the same problem. Is there a performance Hit over one. I am using SQL server and I tend to use FOR XML PATH(”) to select multiple columns that occur in subqueries. Any example to explain the difference will be appreciated.
Please can anyone give me the difference between using a Correlated sub-query over a
Share
“Please can anyone give me the difference between using a Correlated sub-query over a JOIN ? Are they not meant to solve the same problem ?”
No they aren’t.
With correlated subqueries, you get an expression for an invocation of either the SEMIJOIN or else the SEMIMINUS of the relational algebra. (Note that I’m talking here of the most typical use of correlated subqueries.)
gives you only the columns that appear in A1. Unlike what you would get if you wrote the JOIN
which would also give you any additional columns from A2 that do not appear in A1.
And
also involves a correlated subquery, but this time it is a semiminus invocation which cannot even be written as a JOIN.
And finally, correlated subqueries can also appear in the SELECT list.
In this case too, many queries of this nature cannot be written as a JOIN.