我有这些表格:
single_user_has_university_has_course
single_user_users_id_user university_has_course_university_id_university university_has_course_course_id_course first_year_school last_year_school grade
1 1 1 2000 2001 15
和
university_has_course
university_id_university course_id_course
1 1 <<< I want to select this
15 1
1 3
15 3
问题是下面的查询返回course_id_course = 1 but ignore the
university_id_university = 1`的所有行。然后,将返回两行。
查询:
SELECT A.first_year_school, A.last_year_school, A.grade, U.university, C.course, T.type_course
FROM single_user_has_university_has_course A
INNER JOIN university_has_course Q
ON A.university_has_course_course_id_course = Q.course_id_course
INNER JOIN university U
ON Q.university_id_university = U.id_university
INNER JOIN course C
ON Q.course_id_course = C.id_course
INNER JOIN type_course T
ON C.type_course_id_type_course = T.id_type_course
AND A.single_user_users_id_user = ?
答案 0 :(得分:0)
您正在将最后一个表连接到2个约束C.type_course_id_type_course = T.id_type_course AND A.single_user_users_id_user = ?
上的先前联接。我想你想把它写成WHERE子句。所以用以下代码替换你的最后一行:
WHERE A.single_user_users_id_user = ?
但您还没有尝试过滤university_id_university = 1
,因此您可能还想将其添加到WHERE
子句中:
WHERE A.single_user_users_id_user = ? AND Q.university_id_university = ?