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)
 join 2 tables on two values

Author  Topic 

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2010-10-03 : 14:28:12
How can I join 2 tables on the values in two columns?
Table 1 has 4 columns and Table 2 has 3 columns

I'd like to join them on a match in columns T1Col1 / T1Col3 equals T2Col1 / T2Col2

Any help is appreciated.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-10-03 : 15:40:37
SELECT * FROM Table1 T1
INNER JOIN Table2 T2
ON T1.Col1=T2.Col1 AND T1.Col3=T2.Col2
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-10-05 : 07:00:27
Also make sure to use table alias for the columns you select

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -