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 6008795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:52:31+00:00 2026-05-23T01:52:31+00:00

I have a directed graph described by A -> B meaning that there exists

  • 0

I have a directed graph described by A -> B meaning that there exists a connection, always weight 1, FROM A TO B. The problem I want to solve (This is not an academic project) is how can I tell how many common connections there are between two nodes.

To say that in terms of A and B.
There are 2 things that need to get done,
* To look at all of my, B, links coming in (All A’s to some B)
* Count how many common A’s out of all My, Original B, A’s.

I do not know if that makes sense but I’ll show you how far I have come.
* First point.

SELECT A
FROM graph
WHERE B='myid';

As most can tell, part 1 is a very simple question. Part 2 is where things get tricky.
I have been able to get all the A’s with at least 1 connection or more similar.

Second point.

SELECT G.A, count( G2.A ) AS common
FROM graph AS G2
JOIN (
    SELECT A, B
    FROM graph
    WHERE B = 'myid'
) AS G ON G.A = G2.B

So the second point is close because it will return all common links, but it will not return all links which have no common links. Is there a way to get that too?


There is still confusion: Ill try to draw a picture… with words.
Here is the table.

A, B
-----   
2, 1  
3, 1  
2, 3

If I wanted to see how many common links from all incoming links into NODE 1 I should see

A, count
---------  
2, 1 // This is for 2's connection to 3.  
3, 0  

With the current SQL statement I have I see this.

A, count
---------  
2, 1 // This is for 2's connection to 3.  
  • 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-05-23T01:52:32+00:00Added an answer on May 23, 2026 at 1:52 am

    Instead of using a subquery, I would just use JOINs:

    SELECT
        N1.A,
        COUNT(N3.A)
    FROM
        Nodes N1
    INNER JOIN Nodes N2 ON
        N2.B = 'myid'
    LEFT OUTER JOIN Nodes N3 ON
        N3.A = N1.A AND
        N3.B = N2.A
    WHERE
        N1.B = 'myid'
    GROUP BY
        N1.A
    

    This gives the answer that you are expecting in your example. You may want to test it out on a wider sample.

    You should also do performance testing on this if your data set is of any significant size.

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

Sidebar

Related Questions

I have a data structure that represents a directed graph, and I want to
I have a data structure that represents a directed graph and I'm looking for
I have a large directed acyclic graph that I would like to visualize in
I have a large directed, acylic graph (DAG) from which I would like to
I have directed graph with lot of cycles, probably strongly connected, and I need
I have a directed graph for all kinds of available address formats in Java,
I have a directed cyclic graph. Some edges are FIXED and may not be
I have an acyclic directed graph. I would like to assign levels to each
Let's say I have an acyclic directed graph such as a family tree (not
I have a large (100,000+ nodes) Directed Acyclic Graph (DAG) and would like to

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.