【发布时间】:2013-04-24 02:52:56
【问题描述】:
我的表名 students 包含字段 student_id、house_id 等。 和科目,房子,学生_科目
我正在使用这个查询
SELECT students_subjects.student_id,students.house_id,students_subjects.subject_id,subjects.subject_name,students.rollno,students.first_name, students.last_name FROM
students_subjects LEFT JOIN students on students_subjects.student_id=students.id
LEFT JOIN subjects on students_subjects.subject_id=subjects.id WHERE students_subjects.class_years_section_id=1
这对我来说很好用..
现在我也想从房屋表中获取房屋名称
我试过这个查询
SELECT students_subjects.student_id,students.house_id,houses.house_name, students_subjects.subject_id,subjects.subject_name,students.rollno,students.first_name, students.last_name FROM
students_subjects LEFT JOIN students on students_subjects.student_id=students.id
LEFT JOIN subjects on students_subjects.subject_id=subjects.id
在students.house_id=houses.id 上左连接房屋 WHERE students_subjects.class_years_section_id=1
AND students_subjects.school_session_id=1 AND students.is_active=1
它给了我 house_name = NULL
谁能告诉我如何获得房屋名称。使用连接查询
谢谢
【问题讨论】:
-
这是常见的MySQL knowledge。您不能在
WHERE语句之后放置JOIN。