Re: Two relations from parent table to child table - Mailing list pgsql-novice

From Andreas Kretschmer
Subject Re: Two relations from parent table to child table
Date
Msg-id dd0abaca-fa0c-2a08-b7ef-a84e46146033@a-kretschmer.de
Whole thread Raw
In response to Two relations from parent table to child table  (JORGE MALDONADO <jorgemal1960@gmail.com>)
List 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



pgsql-novice by date:

Previous
From: JORGE MALDONADO
Date:
Subject: Two relations from parent table to child table
Next
From: Tomasz Barszczewski
Date:
Subject: Re: PostgreSQL database for GITLAB - Must it use the public schema?