Обсуждение: Two relations from parent table to child table

Поиск
Список
Период
Сортировка

Two relations from parent table to child table

От
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.
Tables.jpg

Respectfully,
Jorge Maldonado
Вложения

Re: Two relations from parent table to child table

От
Andreas Kretschmer
Дата:

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