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 |
|
sunbeam
Starting Member
8 Posts |
Posted - 2004-08-16 : 10:49:12
|
| i have 2 tables, one is a look up tbl and the other is tbl with datatbllookups_id status------------------0 pass1 failtbldata-------------s_id p_id1 10 11 1i am able to join tbldata and tbllookup for s_idselect p.s_id, s.status, p.p_id from tbldata as pjoin tbllookup s on (p.s_id = s.s_id)how do i get the same for p_id too?thanks |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-08-16 : 10:56:26
|
This work for ya?select t.s_id, s.status, t.p_id, p.statusfrom tbldata as tInner join tbllookup s on t.s_id = s.s_idInner join tbllookup pon t.p_id = p.s_id Corey |
 |
|
|
sunbeam
Starting Member
8 Posts |
Posted - 2004-08-16 : 11:19:57
|
| thank u for that input,the look up seemed to work,except reduced my table from 80 records to 2 ??? |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-08-16 : 11:32:13
|
| Change the 'inner' to 'left':select t.s_id, s.status, t.p_id, p.statusfrom tbldata as tleft join tbllookup s on t.s_id = s.s_idleft join tbllookup pon t.p_id = p.s_idCorey |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-16 : 11:36:24
|
| you've given use too little to work with. give us more data on table structure and data.Go with the flow & have fun! Else fight the flow :) |
 |
|
|
sunbeam
Starting Member
8 Posts |
Posted - 2004-08-16 : 12:21:26
|
| here u go, for the db structuretblStatus is linked to tblC which is linked to two tables(inner)1)tblP1(needs to call 2 look up tables tblLookUp1, tblLookup2)2)tblP2my above post was in regards to tblstausmy entire join statement looks like this:select whatever from tblStatus sright join tblC c(inner join tblP1(left join tblLookup1, left join tblLookup2)inner join tblP2)where (s.id = c.id)any suggestions if this is nested correctly and where should the second insert inner join() tblstatus s1 go?(from ur post) |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-16 : 14:14:18
|
| and this works for you???where are the linking fields??? you need to do select whatever from tblStatus s right join tblC c on (s.id = c.id) inner join tblP1 P1 on (someFields) inner join tblP2 P2 on (someFields) left join tblLookup1 L1 on (someFields) left join tblLookup2 L2 on (someFields)Go with the flow & have fun! Else fight the flow :) |
 |
|
|
|
|
|
|
|