Problem with query select MAX in MySql

2

I have the following query

SELECT 
    h.cod_hoja,p.nombre, 
    p.universidad, 
    d.nombre_diagnostico, 
    h.hojaEvolucion, 
    h.planEvolucion,
    h.fecha_consulta,
    h.hora_consulta 
FROM hoja_evolucion as h 
    JOIN paciente_hoja as ph on ph.cod_hojaFK = h.cod_hoja 
    JOIN pacientes as p on p.cedula= ph.cedulaFK 
    JOIN citas as c ON c.cedulaFK = p.cedula 
    JOIN diagnostico as d ON c.cod_diagnosticoFK = d.cod_diagnostico 
WHERE h.cod_hoja = (select MAX(cod_hoja) from hoja_evolucion)

I need that in theory I return the data selected from the last record inserted in sheet_evolution. Dog is returning two records to me the same leaf_code, which I do not know why it happens, since leaf_code is the primary key, so it can not be repeated.

    
asked by Oscar Alberto Rodriguez 15.12.2018 в 04:07
source

1 answer

0

select leaf_code from leaf_evolution WHERE leaf_code = 23;

To know that there is only one record, if this brings you a single record you should see your query because it must have something wrong.

  • correction: the max works well what happens is that you have a bridge in the secure join in an appointment there is one or several diagnosis if the image you put does not repeat the row because in the diagnostic name they are different you have diagnosis 1 and diagnosis 2. and that is correct.
answered by 15.12.2018 в 23:42