Re: Two relations from parent table to child table

From: Andreas Kretschmer <andreas(at)a-kretschmer(dot)de>
To: pgsql-novice(at)lists(dot)postgresql(dot)org
Subject: Re: Two relations from parent table to child table
Date: 2019-01-22 05:43:45
Message-ID: dd0abaca-fa0c-2a08-b7ef-a84e46146033@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Am 22.01.19 um 02:07 schrieb JORGE MALDONADO:
> Hi,
>
> I have a table of games and a catalog of teams where each game is
> always played by 2 teams. How should I design these tables? Please
> refer to the image below.
>
> I suppose that option #2 is the correct one but I want to make sure it is.
> I have never seen 2 relations from a parent table to a child table.

solution 1 is the correct one.

you have to use 2 joins to select that, and you have to use 2 aliases
for the 2 joins to distinct the team-table. Something like

select ... from ... left join teams t1 on game.team1 = t1.id left join
teams t2 on game.team2=t2.id ...

Andreas

--
2ndQuadrant - The PostgreSQL Support Company.
www.2ndQuadrant.com

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tomasz Barszczewski 2019-01-22 12:11:46 Re: PostgreSQL database for GITLAB - Must it use the public schema?
Previous Message JORGE MALDONADO 2019-01-22 01:07:28 Two relations from parent table to child table