How to generate a query of two foreign keys that point to the same table?

1

I am developing a system to control X services, as I suppose I have a table called ' services ' where I keep all kinds of services, structurally the table is this:

This table contains two fields called fidusuario_recepcion and fidusuario_repacion . The first registers the service and the second attends it, as simple as that. So my problem is, how would my query be to call the fullname field of the two fields mentioned above.

So far, I've made the following statement:

SELECT 'servicios'.'fidusuario_recepcion', 'servicios'.'fidusuario_reparacion', 
'usuarios'.'fullname'  
FROM 'servicios'
LEFT JOIN 'usuarios' on 'servicios'.'fidusuario_reparacion' = 'usuarios'.'idusuario'

And I get the following result:

What is missing from my query or how could I get those two names, given both fields point to the same table? Thank you in advance

    
asked by DaveSanchez 18.09.2016 в 05:37
source

1 answer

1

I have it, you only had to assign an alias for each foreign key, I leave code waiting for them to serve someone in the future:

SELECT 's'.'fidusuario_recepcion', 's'.'fidusuario_reparacion', 'recibe'.'fullname' 
as 'urecepcion', 'repara'.'fullname' as 'urepara' 
FROM 'servicios' 's' 
JOIN 'usuarios' 'recibe' on 's'.'fidusuario_recepcion' = 'recibe'.'idusuario' 
JOIN 'usuarios' 'repara' on 's'.'fidusuario_reparacion' = 'repara'.'idusuario' 
    
answered by 18.09.2016 в 06:05