dbTalk Databases Forums  

SQL help requested - "linked list"

comp.databases.theory comp.databases.theory


Discuss SQL help requested - "linked list" in the comp.databases.theory forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Mia
 
Posts: n/a

Default Re: SQL help requested - "linked list" - 08-22-2003 , 06:07 PM






Thanks everybody (esp. Mikito)!

Using the "connect by" construct does the trick. The information about
using "connect by" talks about family tree and other hierarchies.
Basically my linked list scenario can be treated as one. It's just a
hierarchy with nodes but no branches.

Using the example that Lennart graciously provided, the Oracle version
goes like this:

To go down the list:

select id from list
start with id = 3
connect by prior id = nextid;

and up the list:

select id from list
start with id = 3
connect by id = prior nextid;

Just what I needed! Thanks again.

-Mia


Reply With Quote
  #12  
Old   
Bob Badour
 
Posts: n/a

Default Re: SQL help requested - "linked list" - 08-25-2003 , 04:30 PM






"Mia" <nospam (AT) cox (DOT) net> wrote

Quote:
Bob Badour wrote:

As I recall, the Oracle syntax for expressing recursion uses a CONNECT
BY
clause.

Yes, the CONNECT BY clause lets me do this sort of query.

Au contraire. If you want to get the IDs that come before or to get the
IDs
that come after a particular ID, you care only about order.

Huh?. As I said before, I don't care about the order.
Exactly which ID's did you want again? If you don't care about order, you
obviously can not care about the ID's in the list that come before the given
ID, because then you would be querying based on the order in the list.
Likewise, you can not care about the ID's in the list that come after the
given ID, because again that would depend only on the order of the ID's in
the list.


Quote:
What, if not implicit order, does the juxtaposition of ID and NEXTID
provide?

One of them gives me the ID that precede the entry point; the other
gives me the ones that follow.
How can anything precede or follow without order?


Quote:
One must ask: What does this implicit order mean? How does it arise in
the
first place? If a human puts the rows into some order, upon what
information
does the human base the decisions? Can one represent this information
directly?

I did not design the data model; I'm just trying to do some queries
against it. For my requirements, the order is completely irrelevant.
If you insist.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.