以下の表 1 と表 3 からすべてのデータを取得できるようにしたいのですが、これに加えて、表 2 から最新のアプリケーション ステージも取得したいと考えています。最新のアプリケーション ステージは、各アプリケーションの最大 stage_date を取得することによって決定されます。
表 1: アプリケーション
id | applicant_id | col_x | col_y | col_z
-----------------------------------------
10 300 a b c
11 310 a b c
12 320 a b c
13 330 a b c
14 340 a b c
表 2: application_progress
id | application_id | application_stage | stage_date | stage_notes
------------------------------------------------------------------
1 10 DRAFT 2013-01-01 (NULL)
2 10 APPLICATION 2013-01-14 (NULL)
3 10 PHASE1 2013-01-30 (NULL)
4 11 DRAFT 2013-01-01 (NULL)
4 12 DRAFT 2013-01-01 (NULL)
5 13 DRAFT 2013-01-01 (NULL)
6 14 DRAFT 2013-01-01 (NULL)
7 14 APPLICATION 2013-01-14 (NULL)
編集:3番目のテーブル
表3:応募者
id | applicant_name | applicant_address | programme_id
------------------------------------------------------
300 Applicant 1 abc 1
310 Applicant 2 xyz 2
320 Applicant 3 xyz 2
330 Applicant 4 xyz 2
340 Applicant 5 xyz 2
返されたデータセット
applicant_id | applicant_name | current_stage
---------------------------------------------------------
300 Applicant 1 PHASE1
310 Applicant 2 DRAFT
320 Applicant 3 DRAFT
330 Applicant 4 DRAFT
340 Applicant 5 APPLICATION
これに苦労しています。助けていただければ幸いです。
PS。sqlfiddle の例を挙げようとしましたが、すぐにダウンしました。これまでに回答がなかった場合は、バックアップ時に sqlfiddle で更新します。