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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:18:40+00:00 2026-06-12T03:18:40+00:00

Given three tables Ta, Tb, Tc: Ta(ID, Field1) Tb(ID, Field2) Tc(ID, Field3) Given data

  • 0

Given three tables Ta, Tb, Tc:

Ta(ID, Field1)
Tb(ID, Field2)
Tc(ID, Field3)

Given data example:

Ta
ID Field1
---------
1  A
1  B

Tb
ID Field2
---------
1  C
1  D
2  E

Tc
ID Field3
---------
1  F
2  G
2  H

Question:
How can I join this data to return:

ID Field1 Field2 Field3
-----------------------
1  A      C      F
1  B      D      NULL
2  NULL   E      G
2  NULL   NULL   H

I thought I could achieve this with outer joins but that doesn’t seem to be the case. The order of the groupings doesn’t really matter, as long as I bring back all information without duplicate rows.

Just to clarify. I don’t really mind which combination I get as long as the result set returns all data in the minimum number of rows. Here’s a more realistic example of what I am trying to do:

Given a person, call him John. He has two phone numbers and three email addresses:

PID  Email
---------
John john@test.com
John john@mail.com
John john@john.com

PID  Tel
--------
John 011
John 022

I want to return:

PID  Email         Tel
----------------------
John john@test.com 011
John john@mail.com 022
John john@john.com NULL
  • 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-12T03:18:41+00:00Added an answer on June 12, 2026 at 3:18 am

    You can come close with the following:

    select coalesce(ta.id, tb.id, tc.id), ta.field1, tb.field2, tc.field3
    from (select ta.*, row_number() over (partition by id order by (select NULL)) as seqnum
          from ta
         ) ta full outer join
         (select tb.*, row_number() over (partition by id order by (select NULL)) as seqnum
          from tb
         ) tb
         on ta.id = tb.id and
            ta.seqnum = tb.seqnum
         (select tc.*, row_number() over (partition by id order by (select NULL)) as seqnum
          from tc
         ) tc
         on coalesce(ta.id, tb.id) = tc.id and
            coalesce(ta.seqnum, tb.seqnum) = tc.seqnum
    group by coalesce(ta.id, tb.id, tc.id),
             coalesce(ta.seqnum, tb.seqnum, tc.seqnum)
    order by 1, 2
    

    As I said, though, in my comment, the ordering of rows in a table is not guaranteed, so these may not come out in the order you expect. With your sample data, you could use:

    over (partition by id order by field<n>)
    

    If the fields define the ordering

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

Sidebar

Related Questions

Short question since I don't know how to search for this. Can I re-update
I'm working with three tables which can be summarized as follows: Table1 ( pid
How can I return a list of fields from a given table that contain
I can't really think of the best way to phrase this question, so I'll
I'm given three binary random variables: X, Y, and Z. I'm also given the
I'm simplifying a larger complex problem with the following... Given three arrays of integers,
Given the following strings 7;#User One 7;#User Two;#9;#User Two 7;#User Two;#9;#User Two;#123;#User Three I
Given the following tree structure in Haskell: data Tree = Leaf Int | Node
Given this table structure, I want to flatten out the many-to-many relationships and make
I am submitting a form via jquery form submit. just like this example However,

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.