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)
 joins (again)

Author  Topic 

sqlclarify
Yak Posting Veteran

56 Posts

Posted - 2008-11-06 : 22:49:26
I am having trouble finding out how to join tables. I mean I need help understanding how to find the join criteria between several tables.

If I have 5 tables

select *
from tableA, tableB, tableC, tableD,tableE
where
join1
join2
join3
join4

How do we figure out the joins? Is it always going to be the relationships between the tables? So if we write another query using the same tables are the join criterias going to be the same.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-06 : 23:46:08
first of all what you've given is old way of joins. Laern to use ANSI join syntax as other join syntax wont be supported in future versions of sql server.Rewriting you code, it will be like below

select * 
from tableA
{inner/left/right/full} join tableB
on joincondition1
{inner/left/right/full} tableC
on joincondition2
{inner/left/right/full} tableD
on joincondition3
{inner/left/right/full} tableE
on joincondition4

the join condition is determined by what columns the two tables are related.
Go to Top of Page
   

- Advertisement -