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

  • Home
  • SEARCH
  • 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 6159721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:10:47+00:00 2026-05-23T21:10:47+00:00

Let’s consider two tables: First: Id Data 1 asd 2 buu And Second: UPD:

  • 0

Let’s consider two tables:
First:

Id Data
1  asd
2  buu

And Second:
UPD:

Id Data
10  ffu
11  fffuuu
10001  asd

I want to get a 4-column table looking like this:

Id1  Data1    Id2 Data2
1     asd      10     fuu  
2     buu      11     fffuuu
-1 [any text]  10001   asd

(if the numbers of rows are not equal ,let’s use “-1” for the id)
How to do this?

I’m using sqlite3-3.7.3.

UPD2:
There is no matching criteria between tables,any random matching between them will be sufficient for me.

  • 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-23T21:10:48+00:00Added an answer on May 23, 2026 at 9:10 pm

    Assuming that the id columns are unique and not null, you can “zip” your tables by:

    1. Creating a row number for each row that corresponds to the
      position of the row when the table is ordered by the unique id (as
      polishchuk mentioned in his comment); and,
    2. Simulating a FULL OUTER JOIN with 2 LEFT OUTER JOINS.

    To demonstrate, I used two tables with differing row counts:

    CREATE TABLE foo (id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT);
    INSERT INTO foo VALUES (NULL, 'a');
    INSERT INTO foo VALUES (NULL, 'b');
    INSERT INTO foo VALUES (NULL, 'c');
    INSERT INTO foo VALUES (NULL, 'd');
    INSERT INTO foo VALUES (NULL, 'e');
    INSERT INTO foo VALUES (NULL, 'f');
    INSERT INTO foo VALUES (NULL, 'g');
    INSERT INTO foo VALUES (NULL, 'h');
    INSERT INTO foo VALUES (NULL, 'i');
    INSERT INTO foo VALUES (NULL, 'j');
    DELETE FROM foo WHERE data IN ('b', 'd', 'f', 'i');
    
    CREATE TABLE bar (id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT);
    INSERT INTO bar VALUES (NULL, 'a');
    INSERT INTO bar VALUES (NULL, 'b');
    INSERT INTO bar VALUES (NULL, 'c');
    INSERT INTO bar VALUES (NULL, 'd');
    INSERT INTO bar VALUES (NULL, 'e');
    INSERT INTO bar VALUES (NULL, 'f');
    INSERT INTO bar VALUES (NULL, 'g');
    INSERT INTO bar VALUES (NULL, 'h');
    INSERT INTO bar VALUES (NULL, 'i');
    INSERT INTO bar VALUES (NULL, 'j');
    DELETE FROM bar WHERE data IN ('a', 'b');
    

    To obtain a more readable output, I then ran:

    .headers on
    .mode column
    

    Then you can execute this SQL statement:

    SELECT COALESCE(id1, -1) AS id1, data1, 
           COALESCE(id2, -1) as id2, data2 
    FROM (
        SELECT ltable.rnum AS rnum, 
               ltable.id AS id1, ltable.data AS data1, 
               rtable.id AS id2, rtable.data AS data2
        FROM
            (SElECT (SELECT COUNT(*) FROM foo 
                WHERE id <= T1.id) rnum, id, data FROM foo T1
            ) ltable
            LEFT OUTER JOIN
            (SElECT (SELECT COUNT(*) FROM bar 
                WHERE id <= T1.id) rnum, id, data FROM bar T1
            ) rtable
            ON ltable.rnum=rtable.rnum
        UNION
        SELECT rtable.rnum AS rnum, 
               ltable.id AS id1, ltable.data AS data1, 
               rtable.id AS id2, rtable.data AS data2
        FROM
            (SElECT (SELECT COUNT(*) FROM bar 
                WHERE id <= T1.id) rnum, id, data FROM bar T1
            ) rtable
            LEFT OUTER JOIN
            (SElECT (SELECT COUNT(*) FROM foo 
                WHERE id <= T1.id) rnum, id, data FROM foo T1
            ) ltable
            ON ltable.rnum=rtable.rnum)
    ORDER BY rnum
    

    Which gives you:

    id1         data1       id2         data2     
    ----------  ----------  ----------  ----------
    1           a           3           c         
    3           c           4           d         
    5           e           5           e         
    7           g           6           f         
    8           h           7           g         
    10          j           8           h         
    -1                      9           i         
    -1                      10          j    
    

    This works “both ways”, for example, if you invert the two tables (foo and bar), you get:

    id1         data1       id2         data2     
    ----------  ----------  ----------  ----------
    3           c           1           a         
    4           d           3           c         
    5           e           5           e         
    6           f           7           g         
    7           g           8           h         
    8           h           10          j         
    9           i           -1                    
    10          j           -1                  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm building a data access layer for an application. Typically I have
Let's say I have a drive such as C:\ , and I want to
Let's consider the following 3 code lines: struct stat buffer; status = lstat(file.c_str(), &buffer);
Let's say I have saved this kind of data (some text '.date(d).' some text)
Let's consider the following scenario: I've a master table with a detail table. The
Let say I have two UIViews: View1: - bounds: 0, 0, 20, 20 -
Let's assume I want to deserialize this (I've removed the namespaces to make things
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's consider a simple grid, where any point is connected with at most 4
Let's say the Activity I want to start is named OccupyThePieShop I was previously

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.