FK from the same table, show data

1

Could someone help me with the sentence?

I would like the nIdePadre = '1' to show in another column the description of nIdeArea = '1' , and more or less it looks like this:

nIdarea  --- nIdePadre --- nIdeEmpresa --- VDescripcion -- vDescrPadre
  1                                         PepitoPerez...
  2            1                            Tienda Arequipa     Pepito Perez 
  3            1                            Tienda Olivos       Pepito Perez

Is this possible?

The nIdePadre and nIdeEmpresa are FK of nIdarea .

    
asked by Jorge Cabrera 22.05.2018 в 19:33
source

1 answer

1

Yes, you can do a JOIN to the same table ...

Something like this:

select A.nIdarea, A.nIdePadre, A.nIdeEmpresa, A.vDescripcion, B.vDescripcion as vDescrPadre
from NombreTabla A join NombreTabla B on A.nIdePadre = B.nIdarea

where NombreTabla is the name of your table (you did not say which is ...).

    
answered by 22.05.2018 / 19:40
source