Skip to content
Advertisement

SQL left join is not including all records from left table

I have a requirement to get monthly total hours worked on different tasks for each employee. For that purpose I am writing a stored procedure. But left join is not populating all record from employee table. I know somehow the where condition is filtering out the null values but I really don’t know how to overcome this problem.

END

Advertisement

Answer

Once you use left join in a from clause, you normally continue with left join. This is critical if the second table is used for any conditions.

Then, any filtering conditions on any of the left join’ed tables need to be in the on clauses, not the where clause. So:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement