简体   繁体   中英

mysql join not working as expected

i want to select schedule of specific teacher for a given day .... statement should assume that a teacher may teach in elementary and high school

here is my statement

 `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 (table) has tables class, teachers, section schedule (table) has tables class_teachers_section, day, time_range

output

在此处输入图片说明

expected result

only one row (last row) with time_start (14:00) time_end (15:00) should have data in columns subject_classmodel_name, subject_teachers_name, subject_section_name, subject_ref, time_ref and day_ref. the rest should be null

Im using MYSQL 5.6.

I think it's not working because of you are missing "ON" statement

the right syntax is

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM