LEARN · SQL · PRACTICE
50 SQL Practice Questions
Five levels, basic SELECT statements to joins, subqueries, and table constraints. Every question has a real solution, an explanation, and its expected output, all against one fixed sample dataset below.
Beacon Robotics' schema, the same one used throughout this course, with a small, fixed set of rows so every question's expected output below is exact and checkable.
| id | name |
|---|---|
| 1 | Engineering |
| 2 | Sales |
| 3 | HR |
| 4 | Finance |
| 5 | Legal |
| id | name | dept_id | salary |
|---|---|---|---|
| 1 | Grace | 1 | 99000 |
| 2 | Noah | 1 | 82000 |
| 3 | Priya | 1 | 76000 |
| 4 | David | 2 | 68000 |
| 5 | Fatima | 2 | 71000 |
| 6 | Carlos | 3 | 59000 |
| 7 | Aisha | 3 | 61000 |
| 8 | Tom | 4 | 76000 |
| 9 | Sofia | 4 | 70000 |
| 10 | Meera | 1 | 85000 |
0 / 50 marked solved
Self-reported, not auto-graded, there's no live SQL engine behind this page. Check your own query against the shown solution and expected output, then mark it yourself. Saved only in this browser.
Level 1 · SQL Basics
Q1–15 · BeginnerSELECT, WHERE, ORDER BY, DISTINCT, LIKE, BETWEEN, IN.
Every Employee
Display every column for every row in the employees table.
Just Name and Salary
Display only each employee's first name, last name, and salary.
Salary Above 70000
Find every employee earning more than 70000.
Engineering Only
Find every employee in department_id 1 (Engineering).
Lowest Salary First
Display every employee ordered by salary, lowest first.
Highest Salary First
Display every employee ordered by salary, highest first.
Distinct Departments
Display every distinct department_id that actually has an employee in it.
A Salary Range
Find every employee whose salary is between 70000 and 80000, inclusive.
Two Departments at Once
Find every employee in department_id 1 or department_id 2.
Names Starting With A
Find every employee whose first name starts with the letter A.
Names Ending in 'a'
Find every employee whose first name ends with the letter a.
Names Containing 'a'
Find every employee whose first name contains the letter a anywhere.
The First Three Employees
Display the first three employees, ordered by id.
Combining Two Conditions
Find every employee earning more than 70000 who's also in Engineering (department_id 1).
Renaming a Column With an Alias
Display every employee's salary under the column name annual_salary instead of salary.
Level 2 · Operators and Data Manipulation
Q16–25 · BeginnerOR, NOT, INSERT, UPDATE, DELETE, and NULL.
Sales or Finance
Find every employee in Sales (department_id 2) or Finance (department_id 4).
Everyone Except Engineering
Find every employee who is not in Engineering (department_id 1).
Outside a Salary Range
Find every employee whose salary is NOT between 70000 and 80000.
A Friendlier Column Name
Display every first name under the alias employee_name.
Counting Everyone
Count the total number of employees.
Hiring a New Employee
Insert a new employee: Liam O'Brien, department_id 2 (Sales), salary 65000, hired 2026-01-15, reporting to employee id 4.
Giving Grace a Raise
Update employee id 1 (Grace Hopper)'s salary to 105000.
Transferring an Employee
Move employee id 3 (Priya Sharma) to department_id 2 (Sales).
An Employee Leaves
Delete employee id 7 (Aisha Bello) from the employees table.
Employees With No Manager
Find every employee whose manager_id is NULL (the department heads).
Level 3 · Aggregate Functions and Grouping
Q26–35 · IntermediateMIN, MAX, SUM, AVG, COUNT, GROUP BY, and HAVING.
The Highest Salary
Find the single highest salary in the company.
The Lowest Salary
Find the single lowest salary in the company.
Total Payroll
Calculate the total of every employee's salary.
Average Salary
Calculate the average salary across the whole company.
Headcount Per Department
Count how many employees are in each department.
Average Salary Per Department
Find the average salary within each department.
Departments With More Than One Employee
Find every department that has more than one employee.
Departments Earning Above 70000 on Average
Find every department whose average salary is greater than 70000.
The Second-Highest Salary
Find the second-highest salary in the company, without a window function.
Departments Ranked by Headcount
List every department's headcount, largest department first.
Level 4 · Joins and Subqueries
Q36–45 · IntermediateINNER/LEFT JOIN, EXISTS, ANY, ALL, and correlated comparisons.
Employees With Department Names
Display every employee's name alongside their department's actual name, not just its id.
Every Department, Even Empty Ones
Display every department alongside each of its employees, including a department with no employees at all.
Departments With Zero Employees
Using the same LEFT JOIN idea, find which departments have no employees at all.
Engineering, via a Join
Find every employee in the Engineering department, by joining on the department's name instead of filtering by department_id.
Above-Average Earners
Find every employee earning more than the company-wide average salary.
Same Department as Grace
Find every employee in the same department as Grace Hopper, excluding Grace herself.
The Top Earner
Find the employee (or employees) earning the single highest salary.
Beating at Least One Sales Salary
Find every employee earning more than at least one employee in Sales (department_id 2).
Beating Every Sales Salary
Find every employee earning more than every employee in Sales (department_id 2).
Departments That Actually Have Staff
Find every department that has at least one employee, using EXISTS instead of a JOIN.
Level 5 · Table Creation and Constraints
Q46–50 · IntermediateCREATE TABLE, ALTER TABLE, DROP TABLE, and foreign keys.
A New Table for Job Candidates
Create a candidates table with an id, full name, the role applied for, and the department it's for.
A Table With NOT NULL and UNIQUE
Create an employee_accounts table where username is required and must be unique, and email is required.
Adding a New Column
Add a phone column to the existing employees table.
Removing a Table
Delete the candidates table created in question 46.
A Table Linked by Foreign Key
Create an expense_claims table where every claim references a real employee by id.
- Write your own query first, against the sample dataset shown above, before revealing the solution.
- Run it for real in a free online playground (linked below) to actually confirm your output.
- If your query differs from the shown solution but gets the same result, that's fine, more than one correct query usually exists.
- When a question trips you up, use its lesson link to review that exact topic before retrying.
Run These for Real
Create the sample tables above in a free SQL playground, then try each question yourself before checking the solution. Pick one based on which database you want to practice on.
Both open a third-party SQL playground in a new tab. External site terms and privacy policy apply.