Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The problem

I have to make a SQL (postgres) query, to show the names of players, whose teams participate in the "Primeira Liga" and the "Ta?a de Portugal". Also, include the names of players of "Académica" club and all of teams founded in the 1940s. Image of Database design

I'm really stuck and can't figure out, how to connect all tables. Does anyone know how to solve the problem?

Thanks in advance.

enter image description here

Updated (10/01/2021): ** I had to change the names to match my DB, so everyone can understand.

DB

question from:https://stackoverflow.com/questions/65649237/sql-how-can-i-join-different-tables-from-competition-of-football

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
394 views
Welcome To Ask or Share your Answers For Others

1 Answer

(SELECT DISTINCT j.nome 
FROM jogador as j 
INNER JOIN equipa as E 
ON E.id = j.equipa_id 
INNER JOIN competicao_equipa as eq 
ON E.id = eq.equipa_id 
WHERE (eq.competicao_id = 1 OR eq.competicao_id = 3))

UNION 

(SELECT j.nome
FROM jogador as j
where equipa_id = 1)

UNION

(SELECT j.nome
FROM jogador as j,equipa
where equipa.fundacao BETWEEN '01/01/1940' AND '31/12/1949')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...