all groups > sql server programming > september 2007 >
You're in the

sql server programming

group:

Simple Q:



Re: Simple Q: Quentin Ran
9/21/2007 2:20:47 PM
sql server programming: You can, but whether you should is a question of performance tuning -- e.g.,
if the data you retrieve with the derived table is to be used multiple
times, you may want to put it into a temp table or into a table type
variable.

Quentin

[quoted text, click to view]

Simple Q: Ana
9/21/2007 7:03:18 PM
Hi,
When joining two queries in one, I understand that the format is as follows:

SELECT *
FROM (<first query here>) as A
JOIN (<second query here>) as B
ON A.ID = B.ID

What would be the format when joining more then 2 queries?
I'm having a problem with the ON syntax when a third (or fouth) query is
added.
TIA,
Ana
Re: Simple Q: Karl Gram
9/21/2007 7:07:45 PM
I assume you mean joining tables?

SELECT *
FROM (<first table here>) as A
JOIN (<second table here>) as B
ON A.ID = B.ID
JOIN (<third table here>) as C
ON A.ID = C.ID
JOIN (<forth table here>) as D
ON C.ID = D.ID

--
HTH,
Karl Gram


[quoted text, click to view]

Re: Simple Q: Tony A
9/21/2007 8:09:21 PM
Huum!
Karl,
Should tables and sub queries mixed in one main query?
Tony

"Karl Gram" <karl@gramonline.nl> escribió en el mensaje de noticias
news:u57NmIH$HHA.4880@TK2MSFTNGP03.phx.gbl...
[quoted text, click to view]
Re: Simple Q: --CELKO--
9/22/2007 6:49:41 AM
[quoted text, click to view]

INNER JOINs do not matter so much, but this infixed syntax can be
tricky when you get to [LEFT | RIGHT | FULL] OUTER JOIN and CROSS
JOIN. The rule is that FROM clause expression is read from left to
right, with the usual rules for parentheses. If a JOIN expression is
given a correlation name, you cannot see any of the table names inside
it. The ON clause is associated with the nearest unmatched JOIN. Two
table expression should not have the same correlation name, etc.
Re: Simple Q: Jack Vamvas
9/22/2007 8:04:04 AM
Could you post what you're doing when you get the error?

--

Jack Vamvas
___________________________________
Need an IT job? http://www.ITjobfeed.com/SQL




[quoted text, click to view]

Re: Simple Q: Tony Rogerson
9/24/2007 4:46:38 PM
[quoted text, click to view]

Really?

FROM x, y, z
WHERE <join>

Or should I really say

FROM x
CROSS JOIN y
CROSS JOIN z
WHERE <join>

As opposed to

FROM x
INNER JOIN y ON <join>
INNER JOIN z ON <join>

IT matters ALOT...

a) VENDOR RECOMMENDATIONS
b) Everybody uses the INNER JOIN style
c) Mixing the <join> with the <filter> leads to people making the
cartisian product mistake

Would you like to start another thread on this?

--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson
[Ramblings from the field from a SQL consultant]
http://sqlserverfaq.com
[UK SQL User Community]


[quoted text, click to view]
Re: Simple Q: Abby
11/1/2007 4:24:42 PM
Try This

select *
into #temp1
from dbo.EmpCid

select *
into #temp2
from dbo.EmpCandidate

select *
into #temp3
from dbo.EmpEEO

select * from #temp1 a
join #temp2 b on a.cid = b.cid
join #temp3 c on a.cid = c.cid

drop table #temp1
drop table #temp2
drop table #temp3

[quoted text, click to view]

AddThis Social Bookmark Button