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
  • 1
    @nada left and left outer are the same thing – dbajtr Sep 05 '17 at 12:53
  • Please read http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557 and the accepted answer –  Sep 05 '17 at 14:51
  • Which [DBMS](https://en.wikipedia.org/wiki/DBMS) product are you using? Postgres? Oracle? –  Sep 05 '17 at 14:51

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,959
  • 15
  • 26
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
  • 2,024
  • 2
  • 14
  • 22