SQL Interview Questions – Employees With Missing Information

Spread the love

Problem Description –

Write an SQL query to report the IDs of all the employees with missing information. The information of an employee is missing if:

  • The employee’s name is missing, or
  • The employee’s salary is missing.

Return the result table ordered by employee_id in ascending order.

The query result format is in the following example.

Problem Link – Missing Information

Difficulty Level – Easy

Solution –

SELECT
    employee_id
FROM Employees
WHERE employee_id NOT IN (SELECT DISTINCT employee_id FROM Salaries)
UNION
SELECT
    employee_id
FROM Salaries
WHERE employee_id NOT IN (SELECT DISTINCT employee_id FROM Employees)
ORDER BY 1

Rating: 1 out of 5.

Leave a Reply