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 2000 Forums
 SQL Server Development (2000)
 design question

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-07-01 : 07:38:17
Jason writes "I have two tables: Neighbor and Data
Neighbor is set up as follows:
Id, Neighborid
12 , 14
12 , 45
.
.
14 , 12
14 , 26
.
.
etc.

while in Data I have
Id , Data
11 , blah11
12 , blah12
13 , blah13
14 , 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 like

Id Neighbor Data
12 , 14 , blah12
14 , 12 , blah14
45 ,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 now

Thanks 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.



Brett

8-)
Go to Top of Page

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}
Go to Top of Page

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....


Brett

8-)
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-07-01 : 15:13:48
Assuming that if 12,14 exists then so will 14,12

select
id, Neighborid, Data1 = d1.Data, Data2 = d2.Data
from Neighbor n ,
Data d1, Data d2
where d1.id = n.id
and d2.id = n.Neighborid
and 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.
Go to Top of Page
   

- Advertisement -