I'm 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 instead of the numbers returned in pai
and mae
, return the names. However the parent and parent codes are ra
as well and are stored in the same table. Is there any way to return names in place in ra
with a single query?