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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 derived table scope

Author  Topic 

sqlclarify
Yak Posting Veteran

56 Posts

Posted - 2008-09-20 : 21:54:47
Hello,

I have a query of the form

select * from
(select col1,col2,col3
from table a where xxx = '100') der1
join
(select * from
der1)der2
on der1.pk = der2.pk
I get der1 is invalid table.

How do I use a derived table in another derived table? Is it not possible?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-09-20 : 23:24:13
>>Is it not possible?
Not like that, no.

You should not get too "derived table" happy. The Optimizer will not be able to take advantage of indexes, statistics, etc. with derived tables. It can be an effective tool to significantly reduce the number or rows being JOINed but your example is not valid and would not be an effective technique if it was valid.

2005 has a new feature: Common Table Expressions (CTE) which allow referencing a derived table multiple times.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -