i have query:
select `y78f2_students`.`firstname` , `y78f2_students`.`lastname` , `y78f2_students`.`student_id`,`y78f2_attendance`.`is_present`, `y78f2_attendance`.`note`, `y78f2_attendance`.`thedate` `y78f2_students` inner join `y78f2_enrolls` on `y78f2_enrolls`.`student_id` = `y78f2_students`.`student_id` inner join `y78f2_attendance` on `y78f2_attendance`.`student_id` = `y78f2_students`.`student_id` `y78f2_enrolls`.`term` = 'term 2 2016' , `y78f2_enrolls`.`crn_class` = 'math1r1' , `y78f2_attendance`.`thedate` = '2016-01-24' order thedate desc
this query returns rows date '2016-01-24'. 1 row: http://i.imgur.com/jrtbqq0.png
i need show rows term
= 'term 2 2016' , crn_class` = 'math1r1' , date not set yet. in order words want show students in class , if date not set these students yet, show null. like: http://i.imgur.com/jmsusf5.png
so in summary need show rows clause met , date null or not exist yet. how can write query?
try moving conditions related joined tables end of query, table's respective on
clause each join. also, if return records no row yet exists in y78f2_attendance
table, table should left outer
joined, not inner
joined.
select `y78f2_students`.`firstname` , `y78f2_students`.`lastname`, `y78f2_students`.`student_id`,`y78f2_attendance`.`is_present`, `y78f2_attendance`.`note`, `y78f2_attendance`.`thedate` `y78f2_students` inner join `y78f2_enrolls` on `y78f2_enrolls`.`student_id` = `y78f2_students`.`student_id` , `y78f2_enrolls`.`crn_class` = 'math1r1' left outer join `y78f2_attendance` on `y78f2_attendance`.`student_id` = `y78f2_students`.`student_id` , (`y78f2_attendance`.`thedate` null or `y78f2_attendance`.`thedate` = '2016-01-24') `y78f2_enrolls`.`term` = 'term 2 2016' order thedate desc
Comments
Post a Comment