Subconsultation with LEFT JOIN

0

The problem is that the subquery does not get anything: What I want to get in the column [rs] is the name of the bank, it is currently returning null.

   SELECT ta.id
    ,ta.idTarea 
    ,ta.idConsignacion
    ,nomBanco.rs
    FROM tarea_actividad AS ta
    LEFT JOIN (SELECT cl.razon_social  rs,
       cg.bancoDestino  cb 
       FROM consignacion cg INNER JOIN cliente  cl ON (cg.bancoDestino=cl.id)) AS nomBanco 
    ON (ta.idConsignacion=nomBanco.cb)
    WHERE ta.idTarea=333

in the table clientes.razon_social refers to the names of the banks: bbva, popular, bancolombia.

and clients.constitution: it is the way to differentiate if the client is a company or a person: natural / legal

Here is the structure of the tables

link

Thank you very much!

    
asked by roca33scorpio 06.02.2018 в 16:09
source

1 answer

0

Yes, good night! I want to share the answer to the question I had asked, maybe it could be useful to another person who is starting, as is my case. Many thanks to everyone who commented, gave me clues to the solution.

SOLUTION 1:

SELECT nomBanco.t0 AS id, nomBanco.t3 AS idTarea, nomBanco.t1 AS idConsignacion, cliente.razon_social AS rs
FROM (SELECT tarea_actividad.id t0,tarea_actividad.idConsignacion t1, consignacion.bancoDestino t2, tarea_actividad.idTarea t3
      FROM tarea_actividad 
      INNER JOIN consignacion ON tarea_actividad.idConsignacion=consignacion.id) AS nomBanco
INNER JOIN cliente ON nomBanco.t2 = cliente.id
WHERE nomBanco.t3=333

SOLUTION 2:

SELECT ta.id
,ta.idTarea 
,ta.idConsignacion
,nomBanco.rs
FROM tarea_actividad AS ta
INNER JOIN (SELECT cliente.razon_social rs,consignacion.id AS idecong FROM consignacion INNER JOIN cliente ON consignacion.bancoDestino=cliente.id) AS nomBanco ON ta.idConsignacion=nomBanco.idecong 
WHERE ta.idTarea=333
    
answered by 07.02.2018 в 05:40