mysql join没有按预期工作

时间:2014-09-04 08:31:56

标签: mysql join

我想在某一天选择特定教师的时间表....声明应该假设教师可以在小学和高中教学

这是我的陈述

 `select 
   class.name as subject_classmodel_name, 
   teachers.name as subject_teachers_name, 
   section.name as subject_section_name, 
   day.name as day_name,
   time_format(time_range.time_start,'%H:%i') as time_time_start,
   time_format(time_range.time_end,'%H:%i') as time_time_end,
   sched.subject_ref, sched.time_ref, sched.day_ref
   from schedule sched
   join class_teachers_section
   join time_range
   join day
   join class
   join teachers
   join section
   where teachers.name = "ronald manlapao" and 
   section.level = "elementary" and 
   time_range.level = "elementary" and 
   class_teachers_section.id = sched.subject_ref and 
   class.id = class_teachers_section.class_ref  and 
   teachers.id = class_teachers_section.teachers_ref and 
   section.id = class_teachers_section.section_ref and
   day.id = sched.day_ref
   order by time_range.time_start asc`

class_teachers_section(表)有表类,教师,部分 schedule(table)有table_teachers_section表,day,time_range

输出

enter image description here

预期结果

只有一行(最后一行),time_start(14:00)time_end(15:00)应该包含subject_classmodel_name,subject_teachers_name,subject_section_name,subject_ref,time_ref和day_ref列中的数据。其余的应该是空的

我正在使用MYSQL 5.6。

1 个答案:

答案 0 :(得分:0)

我认为这是行不通的,因为你缺少“ON”声明

正确的语法是

SELECT field FROM tableA
JOIN tableB
ON tableA.id = tableB.id