Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rn5a
Starting Member
25 Posts |
Posted - 2008-10-27 : 01:46:28
|
| Often I see queries using subqueries wherein the subquery comes in the FROM clause &/or in the WHERE clause. How do I understand when to put the subquery in the FROM clause & when to put the subquery in the WHERE clause?Thanks,Ron |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-27 : 02:08:25
|
A "subquery" in the FROM part is called a derived table and is evaluated once.A correlated subquery (in the SELECT part) is evaluated for every record.A correlated subquery (in the WHERE part) is evaluated for every record. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-27 : 02:09:29
|
| depends on your scenario. If you want some grouping or aggregation to be performed on a table and then take the aggregated results to join to another table thats when you use subquery in FROM clause. Its actually called a derived table. Whenever you want to select fields from one table based on existence of a particular field or query condition, that when you use subquery in where clause. |
 |
|
|
|
|
|