次のデータベース テーブルと列があります。
students
+------------+-------------------+------------------+
| student_id | student_firstname | student_lastname |
+------------+-------------------+------------------+
| 95 | John | Doe |
+------------+-------------------+------------------+
studentcourseplan
+--------+------------+
| cpl_id | student_id |
+--------+------------+
| 209 | 95 |
| 273 | 95 |
+--------+------------+
studentdates
+------------+-------------------+-----------------+
| student_id | student_startdate | student_enddate |
+------------+-------------------+-----------------+
| 95 | 2012-07-02 | 2012-08-17 |
| 95 | 2012-08-20 | 2012-11-16 |
+------------+-------------------+-----------------+
このクエリを実行すると...
SELECT
scp.cpl_id,
s.student_id,
s.student_firstname,
s.student_lastname,
sd.student_startdate,
sd.student_enddate
FROM
studentcourseplan scp
INNER JOIN
students s ON s.student_id = scp.student_id
INNER JOIN
studentdates sd ON sd.student_id = s.student_id
...次の出力が得られます。
+--------+------------+-------------------+------------------+-------------------+-----------------+
| cpl_id | student_id | student_firstname | student_lastname | student_startdate | student_enddate |
+--------+------------+-------------------+------------------+-------------------+-----------------+
| 209 | 95 | John | Doe | 2012-07-02 | 2012-08-17 |
| 273 | 95 | John | Doe | 2012-07-02 | 2012-08-17 |
+--------+------------+-------------------+------------------+-------------------+-----------------+
表の値と比較した結果の日付に注目してくださいstudentdates
。彼らは間違ってる。代わりに、次のような出力が必要です。
+--------+------------+-------------------+------------------+-------------------+-----------------+
| cpl_id | student_id | student_firstname | student_lastname | student_startdate | student_enddate |
+--------+------------+-------------------+------------------+-------------------+-----------------+
| 209 | 95 | John | Doe | 2012-07-02 | 2012-08-17 |
| 273 | 95 | John | Doe | 2012-08-20 | 2012-11-16 |
+--------+------------+-------------------+------------------+-------------------+-----------------+
私は何を間違っていますか?