Re: combination join against multiple tables

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Geoff Winkless <pgsqladmin(at)geoff(dot)dj>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: combination join against multiple tables
Date: 2020-01-31 15:25:07
Message-ID: CAKFQuwbp356YLQOESo0Ygc6y0=EU0XOk=TiMt+NUoE7UFdvZ5g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Friday, January 31, 2020, Geoff Winkless <pgsqladmin(at)geoff(dot)dj> wrote:

> Now the problem is that I would like to return all the rows from a, but
> with a single row where t2.b and t1.b match.
>

So, the final,number of rows for each “a” is the larger row count of “b”
and “c” having the same “a”. Furthermore for the first “n” rows “b” and
“c” should be paired together by position. The smaller count column just
gets nulls for the extra rows.

Probably the easiest way is to combine the matches for “b” and “c” into
arrays the jointly unnest those arrays in the final result - with in the
select list or maybe as part,of a lateral join, not sure without
experimentation.

Otherwise you can add “row_number” to “b” and “c” and then left join on (a,
row_number).

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Geoff Winkless 2020-01-31 15:34:44 Re: combination join against multiple tables
Previous Message Geoff Winkless 2020-01-31 14:01:17 combination join against multiple tables