How to select in a table as if it were two registers

0

In the person table you have the following information

ID  |  NOME  |  É_ALUNO  |  É_RESPONSAVEL
1   |  ALUNO |  TRUE     |  FALSE
2   |  RESPON|  FALSE    |  TRUE

There is another table with the name responsavel_aluno , this table has the following information;

ID   |   ALUNO   |   RESPONSAVEL
1    |   1       |   2

I'd like to give a select as below:

NOME   |  ALUNO
RESPON |  ALUNO

What is the best way to give this select?

    
asked by anonymous 26.04.2018 / 03:28

2 answers

2

I think this select can help:

SELECT a.nome AS aluno_nome, r.nome AS responsavel_nome
FROM pessoa a, pessoa r, responsavel_aluno ra
WHERE r.e_responsavel = true AND a.e_aluno = true AND ra.aluno = a.id AND ra.responsavel= r.id
    
26.04.2018 / 04:21
3

Using INNER JOIN :

SELECT p.nome AS aluno, r.nome AS responsavel
FROM pessoa p
INNER JOIN responsavel_aluno r ON p.id = r.responsavel
WHERE p.e_responsavel = true
    
26.04.2018 / 05:11