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 2008 Forums
 Transact-SQL (2008)
 join 3 tables

Author  Topic 

nikoz
Yak Posting Veteran

63 Posts

Posted - 2013-03-02 : 14:21:33
How to join 3 tables in one?
Tables is something like this

table1

city adress work post_office_number E-mail


table2

city adress work


table3

city adress E-mail company

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-02 : 22:43:29
should be like

select required columns
from table1 t1
inner join table2 t2
on t2.city = t1.city
and t2.adress = t1.adress
and t2.work = t1.work
inner join table3 t3
on t3.city = t1.city
and t3.adress = t1.adress
and t3.[E-mail] = t1.[E-mail]


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

Go to Top of Page

nikoz
Yak Posting Veteran

63 Posts

Posted - 2013-03-03 : 12:30:02
Yes but I want all colums in results
like this

city adress work post_office_number e-mail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-03 : 22:45:36
put columns in select list


select t1.city, t1.adress, t1.work, t1.post_office_number, t3.e-mail
from table1 t1
inner join table2 t2
on t2.city = t1.city
and t2.adress = t1.adress
and t2.work = t1.work
inner join table3 t3
on t3.city = t1.city
and t3.adress = t1.adress
and t3.[E-mail] = t1.[E-mail]


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

Go to Top of Page
   

- Advertisement -