У меня здесь пять таблиц:
Пользователь
+--------+----------+
| stu_id | batch-id |
+--------+----------+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
+--------+----------+
subject_id
+------------+--------------+
| subject_id | subject_name |
+------------+--------------+
| 1 | mathematics |
| 2 | science |
| 3 | english |
+------------+--------------+
пакет
+----------+------------+
| batch_id | batch_name |
+----------+------------+
| 1 | 20182019 |
| 2 | 20202021 |
| | |
+----------+------------+
subject_batch
+----------+------------+
| batch_id | subject_id |
+----------+------------+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| | |
+----------+------------+
subject_assessment
+--------+----------+
| stu_id | batch_id |
+--------+----------+
| 1 | 1 |
+--------+----------+
ВЫБРАТЬ, чего я пытаюсь достичь, это
+--------+----------+------------+--------------+
| stu_id | batch_id | subject_id | subject_name |
+--------+----------+------------+--------------+
| 1 | 1 | 1 | mathematics |
| 1 | 1 | 2 | science |
| 1 | 1 | 3 | english |
| | | | |
+--------+----------+------------+--------------+
Я попытался =
$query = "SELECT subject.subject_name, user.first_name, batch.batch_name
from subject_assessment inner join user
ON subject_assessment.student_id = user.user_id inner
join batch ON subject_assessment.batch_id = batch.batch_id
left join subject_batch on = subject.subject_name = subject_batch.subject_id";
, но потерпел неудачу.Это работает, когда я удаляю
subject.subject_name
и
left join left join subject_batch on = subject.subject_name = subject_batch.subject_id"
Но тогда я не смогу получить subject_id и subject_name.
Оценить, если вы могли помочь. Спасибозаранее.