Sobes.tech
Intern — Middle

Employees without assigned department

livecode

Task condition

It is necessary to select all employees whose department_id field is empty or whose value in this field is not found in the departments table.

CREATE TABLE departments (
    id INT PRIMARY KEY,
    name VARCHAR(100) NOT NULL
);

CREATE TABLE employees (
    id INT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    department_id INT,
    FOREIGN KEY (department_id) REFERENCES departments(id)
);