I needed to list, with SQL, the father, mother and spouse of a person together with their general data (eg name, address, telephone, email, father, mother, spouse, status).
This data is in another table called dependent, each one related to the id of the person
At first I thought it was very complicated, I started to search the internet, even here, with no result, so I decided to burn the brain a bit, and I came up with a super simple solution that suited my need:
SELECT
p.nome,
p.endereco,
p.telefone,
p.email,
dp.nome AS nomePai,
dm.nome AS nomeMae,
dc.nome AS conjuge,
p.status,
FROM
pessoa p
JOIN dependente dp ON dp.idPessoa = p.idPessoa AND dp.tipo = 6
JOIN dependente dm ON dm.idPessoa = p.idPessoa AND dm.tipo = 7
JOIN dependente dc ON dc.idPessoa = p.idPessoa AND dc.tipo = 5
Who knows better, just put it there in the comments and help the community