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
 what does this alias do?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tracmonali
Starting Member

16 Posts

Posted - 05/19/2012 :  10:02:04  Show Profile  Reply with Quote
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

Sweden
29138 Posts

Posted - 05/19/2012 :  13:00:44  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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"
Go to Top of Page

tracmonali
Starting Member

16 Posts

Posted - 05/20/2012 :  10:45:03  Show Profile  Reply with Quote
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

India
47173 Posts

Posted - 05/20/2012 :  11:23:43  Show Profile  Reply with Quote
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
  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.08 seconds. Powered By: Snitz Forums 2000