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.
Author |
Topic |
fizzer
Starting Member
10 Posts |
Posted - 2006-09-26 : 05:38:14
|
Hi,Can you have an inner join on more than one column. I have two tables with composite primary keys. I can't create a join on a single column so how would I create the join on two columns?Hope that makes sense |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-09-26 : 05:59:28
|
SELECT *FROM FirstTable ftINNER JOIN SecondTable st ON st.ColA = ft.Col1 AND st.ColB = ft.Col2Peter LarssonHelsingborg, Sweden |
 |
|
fizzer
Starting Member
10 Posts |
Posted - 2006-09-26 : 06:12:57
|
Many thanks. That did the trick. |
 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-09-26 : 08:14:07
|
aha how about this, if both the fields are varchar SELECT *FROM FirstTable ftINNER JOIN SecondTable st ON st.ColA + '-'+ st.ColB = ft.Col1+'-'+ft.Col2 Chirag |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2006-09-27 : 00:18:23
|
quote: Originally posted by chiragkhabaria aha how about this, if both the fields are varchar SELECT *FROM FirstTable ftINNER JOIN SecondTable st ON st.ColA + '-'+ st.ColB = ft.Col1+'-'+ft.Col2 Chirag
Only if you never want to use an index. |
 |
|
|
|
|