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
 General SQL Server Forums
 New to SQL Server Programming
 what does this alias do?

Author  Topic 

tracmonali
Starting Member

16 Posts

Posted - 2012-05-19 : 10:02:04
can somebody help me understand how is this alias for the select stmt diff than a temp table? would putting in a temp table be an optimal solution?
Scenario1:
select * from tabl1
inner join (
select * from table 3
inner join table 4 on table3.col1 = table4.col1) AliasName
on AliasName.col4 = tabl1.col1

Scenario2
Create table #tempAliasName (col1, col2, col3, col4)
insert into #tempAliasName
(select * from table 3
inner join table 4 on table3.col1 = table4.col1)

select * from tabl1
inner join #tempAliasName
on #tempAliasName.col4 = tabl1.col1

Please help me understand the diff between 2 scenarios (wrt optimization, good querying practice, overhead on server) if any?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-05-19 : 13:00:44
[code]SELECT *
FROM dbo.Table1 AS t1
INNER JOIN dbo.Table3 AS t3 ON t2.Col4 = t1.Col1
INNER JOIN dbo.Table4 AS t4 ON t4.Col1 = t3.Col1[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

tracmonali
Starting Member

16 Posts

Posted - 2012-05-20 : 10:45:03
quote:
Originally posted by SwePeso

SELECT		*
FROM dbo.Table1 AS t1
INNER JOIN dbo.Table3 AS t3 ON t2.Col4 = t1.Col1
INNER JOIN dbo.Table4 AS t4 ON t4.Col1 = t3.Col1



N 56°04'39.26"
E 12°55'05.63"




there is no selection from table2??????

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-20 : 11:23:43
quote:
Originally posted by tracmonali

quote:
Originally posted by SwePeso

SELECT		*
FROM dbo.Table1 AS t1
INNER JOIN dbo.Table3 AS t3 ON t2.Col4 = t1.Col1
INNER JOIN dbo.Table4 AS t4 ON t4.Col1 = t3.Col1



N 56°04'39.26"
E 12°55'05.63"




there is no selection from table2??????




there's no table2 in your example

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -