Skip to content
Quantoros

Return the names of employees with no rows in salaryhistory. Table definitions (from the source exercise):

SQLLevel: IntermediateAnti-joins and missing data

Return the names of employees with no rows in salary_history.

Table definitions (from the source exercise):

CREATE TABLE employees(emp_id INTEGER PRIMARY KEY, name TEXT, department_id INTEGER, manager_id INTEGER, salary INTEGER, hire_date TEXT, job_title TEXT, gender TEXT);
CREATE TABLE salary_history(hist_id INTEGER PRIMARY KEY, emp_id INTEGER, change_date TEXT, old_salary INTEGER, new_salary INTEGER);
Hints
  • Define one output row and the source-table keys.
  • Check duplicates, NULLs and the order of filtering and aggregation.

Answer

Approach: LEFT JOIN salary_history; IS NULL.

SELECT e.name
FROM employees e
LEFT JOIN salary_history sh ON sh.emp_id = e.emp_id
WHERE sh.hist_id IS NULL;

The source uses SQLite with a MySQL compatibility layer. Date and string functions are dialect dependent; the query is preserved as published.

Source and licence: SQL Practice Lab — Ebrahim Sharifi · MIT

Related questions