Anudeep Girish
Anudeep Girish

Reputation: 1

retrieving the data from the table

Let us say you have a Table with

Employees (FName, LName, DeptNo, Age, DOB) 

and you have a Table called

Dept(DeptNo, Department Name)

The Challenge is that some of the Employees records do not have any Department No Specified. I want you to retrieve the List of all Employees along with their Department Name. So what would the Query Look Like.

Upvotes: 0

Views: 30

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521103

Use a left join:

SELECT
    e.FName,
    e.LName,
    COALESCE(d.DepartmentName, 'NA') AS DepartmentName
FROM Employees e
LEFT JOIN Dept d
    ON d.DeptNo = e.DeptNo;

Upvotes: 3

Related Questions