I have a 'student' table and 'attendance' table If a student is absent I just enter student ID and date in attendance table. Now I want to retrieve all students and their attendance on a particular date However when I am trying left Join, it gives me data of a particular student absent on that particular date
Table 'student' structure and sample data:
id|name (varchar field)
1 |xxx
6 |yyy
Table 'attendance' structure and sample data:
id|date (date field)|student_id (integer field)
1 |2015-10-15 | 1
1 |2015-10-16 | 6
My query
SELECT *
FROM student.id, student.name, attendance.date
LEFT JOIN attendance
ON student.id = attendance.student_id
WHERE attendance.date = '2015-10-15'
The output is
1 xxx 2015-10-15
However required output is
1 xxx 2015-10-15
6 yyy NULL (or a blank)
ONinstead ofWHERE