Mysql
 sql >> Database >  >> RDS >> Mysql

MySql seleziona tutte le righe in una tabella in base al valore MAX in un'altra tabella

Puoi farlo con una sottoquery correlata:

select a.*,
       (select application_stage
        from application_progress ap
        where ap.application_id = a.id
        order by stage_date desc
        limit 1
       ) MostRecentStage
from applications a;

MODIFICA:

Puoi unirti ai dati del richiedente con qualcosa del genere::

select a.*, aa.*,
       (select application_stage
        from application_progress ap
        where ap.application_id = a.id
        order by stage_date desc
        limit 1
       ) MostRecentStage
from applications a join
     applicant aa
     on a.applicant_id = aa.id;