MySql nested query

-2
  • I have to consult 4 tables of a database in mysql
  • From 3 tables I need to take all the information with a where
  • Of the fourth only take the last record that was entered in the column.

I have the following code

SELECT convenio.nit_Fuente, fuentes.nom_Fuente, convenio.nit_asociado, asociados.Nom_asociado, asociados.Apell_asociado
FROM 'convenio' 
LEFT JOIN 'fuentes' ON (convenio.nit_Fuente = fuentes.nit_Fuente)
LEFT JOIN 'asociados' ON (convenio.nit_asociado = asociados.nit_asociado)
LEFT JOIN (SELECT recibo.num_recibo, MAX(recibo.num_recibo
            FROM recibo                             )
WHERE convenio.nit_asociado = '101244561'
    
asked by Jeferson Martinez 12.08.2016 в 04:21
source

2 answers

1

try this to see

SELECT convenio.nit_Fuente,
       fuentes.nom_Fuente,
       convenio.nit_asociado,
       asociados.Nom_asociado,
       asociados.Apell_asociado,
       recibo.num_recibo
  FROM 'convenio',
       'fuentes',
       'asociados',
       (SELECT recibo.num_recibo,
               MAX(recibo.num_recibo)
          FROM recibo
       )
 WHERE convenio.nit_Fuente   = fuentes.nit_Fuente
   AND convenio.nit_asociado = asociados.nit_asociado
   AND convenio.nit_asociado = '101244561'
    
answered by 12.08.2016 в 11:57
0

the way I solved it was

    SELECT 
    (SELECT MAX(recibo.num_recibo) 
    FROM recibo ) as NumRecibo, Con.nit_Fuente, Fue.nom_Fuente, Con.nit_asociado, Aso.Nom_asociado, Aso.Apell_asociado 
    FROM convenio Con 
    LEFT JOIN fuentes Fue ON (Con.nit_Fuente = Fue.nit_Fuente) 
    LEFT JOIN asociados ASO ON (Con.nit_asociado = Aso.nit_asociado)
 where Con.nit_asociado = '101244561'
    
answered by 12.08.2016 в 21:22