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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:00:40+00:00 2026-06-06T00:00:40+00:00

I have a sqlite table representing a weighted directed graph. The columns are as

  • 0

I have a sqlite table representing a weighted directed graph. The columns are as follows:

node1 | node2 | weight(node1,node2)

Instead I need this table:

node1 | node2 | weight(node1,node2) | weight(node2,node1)

(node2 | node1 | weight(node2,node1) | weight (node1, node2) should not exist in the table)

I am not familiar with SQL that well, so I couldn’t figure out how to make the new table from the original table in sqlite3.

Thanks for your help.

  • 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-06T00:00:42+00:00Added an answer on June 6, 2026 at 12:00 am

    I assume your node1 and node2 are integer foreign keys linking to a node table, and the table you mention is an edge table?

    Assuming the edge table has been created with something like:

    CREATE TABLE edges( node1 INTEGER, node2 INTEGER, weight REAL );
    

    How about something like (assuming no self-arcs and for every link from a->b there is also a link from b->a):

    CREATE TABLE newedges( node1 INTEGER, node2 INTEGER, weight1 REAL, weight2 REAL );
    
    INSERT INTO newedges
        SELECT e1.node1, e1.node2, e1.weight, e2.weight
        FROM edges AS e1 INNER JOIN edges AS e2
        ON e1.node1=e2.node2 AND e1.node2=e2.node1
        WHERE e1.node1 < e1.node2;
    

    The self-join collates forward and backwards edges, and the requirement that e1.node1 is less than e1.node2 ensures that you only see each collated edge once.

    Edit in response to a request to fill in zeros for missing backwards edge:

    For missing backwards edges, you can do a LEFT JOIN and use a CASE statement to fill in the gaps with zeros:

    INSERT INTO newedges
        SELECT
            e1.node1,
            e1.node2,
            e1.weight,
            CASE WHEN e2.weight IS NULL THEN 0.0 ELSE e2.weight END
        FROM edges AS e1 LEFT JOIN edges AS e2
        ON e1.node1=e2.node2 AND e1.node2=e2.node1
        WHERE e1.node1 < e1.node2;
    

    Hope that helps!

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

Sidebar

Related Questions

I need to achieve this: I have a sqlite table with this data slno
i have an sqlite table with 2000 records. I need to show this records
I have a listView with checkbox which populate from sqlite table. I need to
I need help with SQL. I have an sqlite table like so; CREATE TABLE
I have SQLite table with columns id and name. I return array of those
I have a SQLite table called Price like this: date, productId, price ---------------------- 20120601,
I have an sqlite table log that looks like this: ID p_id viewer ----------------------
i have this sqlite table: CREATE TABLE frames (videomd5 TEXT, framemd5 TEXT, type TEXT,
Suppose I have an SQLite table email_db with 2 columns - email and name
I have a sqlite (v3) table with this column definition: timestamp DATETIME DEFAULT CURRENT_TIMESTAMP

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.