1

I have 2 tables First is Employee and Second is Attendance

Employee Table :-

enter image description here

Attendance Table :-

enter image description here

there is only 3 Employee's attendance entered in Attendance Table on AttDate = '2017-09-05'.

i use this query to join these table :-

select EmpName,Attendance from Employee Left join Attendance on Employee.EmpId = Attendance.refId where AttDate ='2017-09-05' 

and it's show this output :-

enter image description here

but i need this output ( employees whose attendance did not enter in Attendance Table will also Show with Null attendance ) :-

enter image description here

what should i change in the query to get this output ?

Vikas Sharma
  • 100
  • 9

2 Answers2

1

If you join on the date value as well, the result set will not be eliminated:

select EmpName,Attendance 
from Employee Left join Attendance on Employee.EmpId = Attendance.refId and AttDate ='2017-09-05' 

You will also get the employees that have not attended on that day. Check out this answer for more info on the difference between having a condition on the where clause vs having it on the on clause.

Rigerta
  • 3,809
  • 12
  • 25
0

You are restricting it with a WHERE so the two EmpID's who didn't do the course on that day wont show up.

You can change your where to:

WHERE AttDate = '2017-09-05' or AttDate is null;

but that will bring back all results who have a null in the date

dbajtr
  • 1,984
  • 2
  • 14
  • 20