Jainam Desai
Jainam Desai

Reputation: 69

How to include Null value in Join?

I have a table where in the column 'AssignedRecruiter' has numerical values (Id). And it can have null values as well.

The Id stored in this column are also present in Employee table which consists of names of Employees. On executing Join between two tables based on Table1.AssignedRecruiter = Employee.Id , I get all the values from Employee table matching with the Id of 'AssignedRecruiter'.

However I wish to have all the null values as well. I tried Left join for picking all value from Table1 but it doesnt work.

Upvotes: 3

Views: 16268

Answers (2)

Ajay2707
Ajay2707

Reputation: 5808

you can use isnull with default value and for join use left join so right table will have data even left does not have.

isnull(Table1.AssignedRecruiter ,0) = isnull(Employee.Id , 0)

Upvotes: 3

Jibin Balachandran
Jibin Balachandran

Reputation: 3441

Use a LEFT JOIN, it will add all the records from table1 to your result set.

SELECT *
FROM table1 t
LEFT JOIN Employee e ON t.AssignedRecruiter = e.Id

Upvotes: 3

Related Questions