Queries between several related tables

0

I have a table actividad that has two attributes: creadoID and modificadoID in relation to the table usuario .

I tried to perform an activities query, where for each record I took the user's data from the person who created it and modified it.

I have the following query:

SELECT * FROM actividad 
INNER JOIN usuario ON actividad.creadoID = usuario.id 
OR actividad.modificadoID = usuario.id
    
asked by Islam Linarez 24.11.2017 в 02:43
source

1 answer

3

What I understand is that you want to check the records in the actividad table. And for each record, you want to see the details of who created and modified it, details that are stored in the usuario table.

The solution is to join the table usuario 2 times:

select a.*,
       c.name as nombre_creador,
       m.name as nombre_modificador
  from actividad a
  join usuario c on c.id = a.creadoID
  join usuario m on m.id = a.modificadoID

Of course, c.name and m.name are just examples because I do not know the names of the columns in your table usuario . Replace my example in SELECT with the columns you need.

    
answered by 24.11.2017 / 02:58
source