Employee Bonus - Problem
Given two tables: Employee and Bonus, write a SQL solution to report the name and bonus amount of each employee who satisfies either of the following conditions:
- The employee has a bonus less than 1000
- The employee did not get any bonus
Return the result table in any order.
Employee Table Schema:
The Employee table contains employee information including their ID, name, supervisor, and salary.
Bonus Table Schema:
The Bonus table contains the bonus amount for some employees. Not all employees may have an entry in this table.
Table Schema
Employee
| Column Name | Type | Description |
|---|---|---|
empId
PK
|
int | Unique employee ID |
name
|
varchar | Employee name |
supervisor
|
int | Supervisor employee ID |
salary
|
int | Employee salary |
Primary Key: empId
Bonus
| Column Name | Type | Description |
|---|---|---|
empId
PK
|
int | Employee ID (foreign key) |
bonus
|
int | Bonus amount |
Primary Key: empId
Input & Output
Example 1 — Mixed Bonus Scenarios
Input Tables:
Employee
| empId | name | supervisor | salary |
|---|---|---|---|
| 3 | Brad | 4000 | |
| 1 | John | 3 | 1000 |
| 2 | Dan | 3 | 2000 |
| 4 | Thomas | 3 | 4000 |
Bonus
| empId | bonus |
|---|---|
| 2 | 500 |
| 4 | 2000 |
Output:
| name | bonus |
|---|---|
| Brad | |
| John | |
| Dan | 500 |
💡 Note:
Brad and John have no bonus records (NULL), so they qualify. Dan has bonus 500 < 1000, so he qualifies. Thomas has bonus 2000 ≥ 1000, so he's excluded.
Example 2 — All Employees No Bonus
Input Tables:
Employee
| empId | name | supervisor | salary |
|---|---|---|---|
| 1 | Alice | 3000 | |
| 2 | Bob | 1 | 2500 |
Bonus
| empId | bonus |
|---|
Output:
| name | bonus |
|---|---|
| Alice | |
| Bob |
💡 Note:
No employees have bonus records, so all employees qualify with NULL bonus values.
Constraints
-
1 ≤ empId ≤ 500 -
nameconsists of lowercase English letters -
1 ≤ salary ≤ 10000 -
1 ≤ bonus ≤ 10000
Visualization
Tap to expand
Understanding the Visualization
1
Input Tables
Employee and Bonus tables
2
LEFT JOIN
Include all employees
3
Filter Results
bonus < 1000 OR NULL
Key Takeaway
🎯 Key Insight: Use LEFT JOIN when you need to include records that may not exist in the second table
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code