Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:51:49+00:00 2026-06-09T15:51:49+00:00

I need to traverse and update the graph in SQL. To put this into

  • 0

I need to traverse and update the graph in SQL.

To put this into prospective, I’ll give an example:

  • Every company can represent other company on a given subject.
  • Companies can represent each other, but not for the same subject

This assumes tables like:

companies(id), representations(source_id, destination_id, subject).

But the rule is that when my company is no longer representing yours on a given subject, then no companies down the chain from mine can represent my company on the same subject.

I hope you understand what I mean.

So with the simple data like:

C1:
--sell--> C2
--pay--> C3

C2:
--sell--> C3
--pay--> C1

C3:
--mail--> C1
--sell--> C4

C4:
--deliver-->C1

Now, we remove the representation (I should have called it relation) C2--sell-->C3 we should end up the following structure ([X] – removed):

C1:
--sell--> C2
--pay--> C3

C2:
[X]--sell--> C3
--pay--> C1

C3:
--mail--> C1
[X]--sell--> C4

C4:
--deliver-->C1

So the question is how is it possible to select all the companies, that are down the chain from mine for a given subject?

I suppose recursive CTE expression is the only way to do it.

NOTES:

  • The structure is not a tree, it is an ordered cyclic graph.
  • Graph database isn’t an option for now (this is only a small part of the system)
  • The updates don’t need to be immediate and it’s ok for them to be eventually consistent (talking about few seconds to minutes).
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:51:51+00:00Added an answer on June 9, 2026 at 3:51 pm

    Sounds like you need to maintain a transitive closure of the graph for each subject. Look at a paper about how to implement an incremental evaluation system (IES) with SQL, seems to be able to do the trick. The paper has extensive SQL examples for directed acyclic, undirected and arbitrary directed graphs.

    It appears that for each of your subject the graph is acyclic, which is fortunately the simplest case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a way to traverse a LINQ-to-SQL expression tree to extract the table
I need to traverse a directed acyclic graph (DAG) using BFS. I am using
I am developing a daily calendar and need to traverse to the next and
I'm developing an app in Android and I need to traverse a xml file.
I need to write a regex, that will traverse through my file and replace
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
Need a map reduce function by mongo in php This my mongo structure [_id]
Need just a push in the right direction with this. I'm building a multi-language
Need help with a query that I wrote: I have three tables Company id
I have this python code that will traverse a tree structure. I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.