I am trying to bring the name of a patient with an inner join to another table but the max() function gives me an error
I try to bring the last patient who was seen by the same doctor and make an inner join to the doctors table to get the name of the doctor
here I already have the error
select id_paciente,max(creado) as fecha from pacientes where referencia=1
I would like it to stay
select d.nombre,max(creado) as fechaultima from doctores d inner join pacientes p on d.id_doctor=p.id_doctor where referencia = 1
You are not referencing the table
pacientes
that contains the fieldcreado
, it should be:Make your query like this:
If you get the error:
use
group by
since in this case an aggregation function is needed: