SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sub-queries in the FROM clause
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nevzab
Starting Member

United Kingdom
34 Posts

Posted - 06/21/2013 :  18:23:48  Show Profile  Reply with Quote
I am trying to understand when sub-queries would be used in the FROM clause of a SELECT statement. Are there circumstances under which you have to use one? I would appreciate any guidance on this subject. Any examples would be a bonus.

Cheers,

Nev.

TG
Flowing Fount of Yak Knowledge

USA
6059 Posts

Posted - 06/21/2013 :  23:31:25  Show Profile  Reply with Quote
There are many circumstances under which you would use a sub-query in a FROM clause. And a sub-query can take numerous forms which is evident when you look at the t-sql reference for FROM. One typical usage is called a "derived table". Those can be used to greatly reduce the number of rows considered before joining to another table. Another reason could be that you want to aggregate some values to narrow down to a group of rows to correlate to another table.

As for examples probably a good thing to do is look through a bunch of sqlteam.com posts. I bet you won't have to look far before seeing some examples.



Be One with the Optimizer
TG
Go to Top of Page

nevzab
Starting Member

United Kingdom
34 Posts

Posted - 06/22/2013 :  06:02:50  Show Profile  Reply with Quote
Thanks for your reply TG. I hadn't go found much info on this subject until you mentioned derived tables, a term I had forgotten about. Now I have read a number of articles on this and related topics, such the difference between correlated and non-correlated sub-queries.

Cheers!

Nev.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000