2
I am creating a view with the following query:
select
COD_PESSOA as ra,
NOM_PESSOA as nome,
COD_PESSOA_PAI as pai,
COD_PESSOA_MAE as mae,
from PESSOA
This query returns a result like this:
ra nome pai mae
1 ciclano 4 5
2 fulano 6 7
3 beltrano 8 9
6 joão NULL NULL
9 maria NULL NULL
I want in place of the numbers returned in pai
and mae
, return the names. But the codes of the father and mother are ra
also and are stored in the same table. Is there any way to return the names instead in ra
with a single consultation?
What is the primary key?
– Victor Stafusa
There is no primary key
– Amanda Lima
So it gets hard, because if the
cod_pessoa_pai
for 4 and when you will look in 4 meets several people with this number, it is impossible to know which one is the father. The same happens with the mother.– Victor Stafusa