TB 1 : user_profile as ur-> id(PK),name (total 4k records all unique)
TB 2 : user_course_rel as ucr-> id,course_id,year_id,division,user_id(Fk)
TB 3 : students_attendance_lect as sal-> id,subject_id,date,student_id(Fk)
student_id(Fk) = user_id(Fk) = id(PK).
I want to left join on TB1 and get name of all students belonging to particular course,year,division and both attendees of subject and date and not attendees which should be 132 unique records.
After running following query i am getting total (4k records)
select distinct(ur.id), ur.fname
from user_profile as ur
inner join user_course_rel as ucr
on ucr.user_id=ur.id
left join students_attendance_lect as sal
on sal.student_id=ucr.user_id
and ucr.course_id=1
and ucr.year_id=1
and ucr.division=3
and sal.subject_id=2
and sal.date='2013-01-21'
Several items in your LEFT JOIN look like they should be in a WHERE clause. I’m not 100% clear what your question is but try:
The way you had written it was asking the DB to LEFT JOIN on any row that had a course id of 1, a division of 3, a subject id of 2 or a date of ‘2013-01-21’, do you see?