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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 join 3 tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nikoz
Yak Posting Veteran

57 Posts

Posted - 03/02/2013 :  14:21:33  Show Profile  Reply with Quote
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

India
52249 Posts

Posted - 03/02/2013 :  22:43:29  Show Profile  Reply with Quote
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/


Edited by - visakh16 on 03/02/2013 22:44:13
Go to Top of Page

nikoz
Yak Posting Veteran

57 Posts

Posted - 03/03/2013 :  12:30:02  Show Profile  Reply with Quote
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

India
52249 Posts

Posted - 03/03/2013 :  22:45:36  Show Profile  Reply with Quote
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
  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.05 seconds. Powered By: Snitz Forums 2000