Skip to content
>_sqlbuddy
easyJOINsLEFT JOINNULL handling

Employee Bonus

Report every employee's name and bonus, including those with none.

Start practice

Prompt

Employee Bonus

Prompt

Given the employee and bonus tables below, write a query that returns every employee whose bonus is less than 1000, or who has no bonus at all.

  • Output columns: name and bonus.
  • An employee with no bonus row (or a NULL bonus) must appear with bonus = NULL.
  • Only the name and bonus columns should be returned.

Example

emp_idnamesalary
1Alice100
2Bob200
3Carol300
emp_idbonus
1500
22000

Expected result:

namebonus
Alice500
Bob2000
CarolNULL

Constraints

  • employee.emp_id and bonus.emp_id are primary keys.
  • bonus.bonus is nullable.

Tips

  • Start from employee with a LEFT JOIN so employees without a bonus still appear.
  • bonus < 1000 alone excludes NULL bonuses — add OR bonus.bonus IS NULL.

Expected concepts

  • LEFT JOIN
  • COALESCE
  • NULL comparison

Schema

CREATE TABLE employee (
    emp_id INTEGER PRIMARY KEY,
    name   TEXT NOT NULL,
    salary INTEGER NOT NULL
);

CREATE TABLE bonus (
    emp_id INTEGER PRIMARY KEY REFERENCES employee(emp_id),
    bonus  INTEGER  -- NULL allowed
);

Sample data

INSERT INTO employee (emp_id, name, salary) VALUES
  (1, 'Alice', 100),
  (2, 'Bob',   200),
  (3, 'Carol', 300),
  (4, 'Dave',  400),
  (5, 'Eve',   500);

INSERT INTO bonus (emp_id, bonus) VALUES
  (1, 500),
  (2, 2000),
  (3, 100),
  (5, 1500);

Additional hidden fixtures are applied during validation to test edge cases.