| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> recursive queries in SQL
Hi,
I'm playing with a (for now) simple model to describe network links/linked objects in an RDBMS (for example, item A connected to B, A connected to C, B connected to C). I'm using the following structure:
table node(node_id,name)
primary key node
table links(node_id1,node_id2) primary key node_id1, nodeid2 foreign key node_id1 references node foreign key node_id2 references node
This model seems to work, except I can't come up with a way to query the data, for example: for a given node, return all connected nodes. I came up with:
select * from nodes, links
where links.node_id1 = nodes.id or links.node_id2 = nodes.id
But this (of course) returns all connected nodes. What are some common ways of querying this type of data?
In case it matters, I'm currently using Sybase SQL Anywhere 6.0.
Thanks
-- Michiel van der KraatsReceived on Thu Nov 15 2001 - 09:08:09 CST
![]() |
![]() |