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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-07-01 : 07:38:17
|
| Jason writes "I have two tables: Neighbor and DataNeighbor is set up as follows:Id, Neighborid 12 , 14 12 , 45 ..14 , 1214 , 26..etc.while in Data I haveId , Data11 , blah1112 , blah1213 , blah1314 , blah14..What I need to do is get Neighbor.Id and its Data as well as Neighbor.Neighborid and its Data so my list would go likeId Neighbor Data12 , 14 , blah1214 , 12 , blah1445 ,12 , blah45...without repeating any Id's; also there is the possibility that some Id's don't have any associated Data so I don't want to include them. Any hints on how to proceed? I am fairly new to SQL and can do basic queries but this seems beyond me right nowThanks for any help you can give" |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-07-01 : 13:51:35
|
| What happened to 12,45?What, in english, are you trying to do.Brett8-) |
 |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2003-07-01 : 14:37:47
|
quote: What I need to do is get Neighbor.Id and its Data as well as Neighbor.Neighborid and its Data so my list would go like Id Neighbor Data 12 , 14 , blah12 14 , 12 , blah14 45 ,12 , blah45
I bolded the above phrase b/c that's where you're throwing people. You're clearly not going for the neighbor ID's data using the above sample rowset.Explain in greater detail what you need.Jonathan{0} |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-07-01 : 14:53:04
|
| Many to many to many....I'd say a data modeling class is in order....Brett8-) |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-07-01 : 15:13:48
|
| Assuming that if 12,14 exists then so will 14,12select id, Neighborid, Data1 = d1.Data, Data2 = d2.Datafrom Neighbor n ,Data d1, Data d2where d1.id = n.idand d2.id = n.Neighboridand n.id < n.Neighborid==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|