Jump to content

Chaining pattern?


svivian

Recommended Posts

This will probably sound quite complex, but it's not really... bear with me...

 

I have some data which is essentially in a chain format. For example: A->B->C or G->F->E where the letters above would be id numbers pointing to rows in another table.

 

So far, I have a table with the values and a table with the relationships, however, I'm not sure of the best way to get a 'chain' from the database.

 

The 'relationship' table has `from` and `to` fields. My 'view' page will be on one of the elements in the chain and I need to get everything else in the chain, given that element (forwards or backwards). So with this system I'd need several queries to find the next/previous element in the chain and keep repeating.

 

I've thought about adding a `root` field to the table to enable me to select all elements of a chain easily, but then the problem is ordering. I suppose in essence this is a tree pattern, is this easily representable in a database?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.