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 |
|
nbs
Starting Member
22 Posts |
Posted - 2007-12-06 : 22:13:54
|
| Hi all... I am trying to get data from three tables. The first two have a field that I can link on to. The 2nd and 3rd have a different field that I can link on to.Table 1 ID1 class12 a13 z14 p15 s16 vTable 2ID1 ID2 category12 34 G213 35 H414 78 A314 96 F415 71 G316 88 J116 89 K1Table 3ID2 Currency34 Rs35 Usd71 Ukp78 Lir88 Mex89 Can96 RrI need to pick ID1 from table 1 and table 2 and then pick the associated ID2 and link it to table 3 to get the currency. I tried...Select table1.class, table2.category, table3.currency from table1, table2, table3 where table1.ID1 = table2.ID1 and table2.ID2 = table3.ID2but it doesnt work right.... |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2007-12-06 : 23:03:53
|
| Do you mean this?Select table1.class, table2.category, table3.currency from table1, table2, table3 where table1.ID1 = table2.ID1 and table2.ID2 = table3.ID2 |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-12-06 : 23:08:03
|
ansi join syntax is preferred:Select table1.class, table2.category, table3.currencyfrom table1join table2 on table1.ID1 = table2.ID1join table3 on table2.ID2 = table3.ID2your query is probably broken because of this: "table2.ID2 = table2.ID3"there is no ID3 column in table2. furthermore you are not referring to table3 anywhere in your where clause. elsasoft.org |
 |
|
|
nbs
Starting Member
22 Posts |
Posted - 2007-12-06 : 23:12:34
|
| My bad... Its table2.ID2= table3.ID2 |
 |
|
|
|
|
|