CmdKeys LogoCommand Quiz

SQL Command Practice

SQL asks a relational engine for rows, not a shell for flags. This track writes SELECT, JOIN, WHERE, GROUP BY, and aggregates against a small company schema and checks the result set, not a multiple-choice guess about syntax.

Command Reference

where

CommandDescription
SELECT name FROM employees WHERE department_id = 1List employees in the Engineering department (department_id 1).
SELECT name FROM employees WHERE salary > 80000List employees earning more than 80,000.
SELECT id, amount FROM orders WHERE status = 'completed'List the id and amount of all completed orders.
SELECT name FROM employees WHERE hire_date > '2020-12-31'List employees hired after 2020.
SELECT id, amount FROM orders WHERE status = 'pending' AND amount > 1000List pending orders with an amount greater than 1,000.

select

CommandDescription
SELECT name FROM employeesList the names of all employees.
SELECT amount FROM ordersList the amount of every order.
SELECT name, salary FROM employeesShow each employee's name and salary.
SELECT name FROM departmentsList the names of all departments.
SELECT DISTINCT status FROM orders ORDER BY statusList each distinct order status in alphabetical order.

aggregate

CommandDescription
SELECT COUNT(id) FROM employeesCount the total number of employees.
SELECT SUM(amount) FROM ordersCalculate the total amount across all orders.
SELECT AVG(salary) FROM employeesCalculate the average employee salary.
SELECT MAX(salary) FROM employeesFind the highest employee salary.
SELECT MIN(amount) FROM orders WHERE status = 'completed'Find the smallest amount among completed orders.

order

CommandDescription
SELECT name, salary FROM employees ORDER BY salary DESCList employees sorted by salary from highest to lowest.
SELECT name FROM employees ORDER BY nameList employee names in alphabetical order.
SELECT amount FROM orders ORDER BY amount ASCList order amounts from lowest to highest.
SELECT name, salary FROM employees ORDER BY salary DESC LIMIT 3List the three highest-paid employees.
SELECT name, budget FROM departments ORDER BY budget DESCList departments sorted by budget from highest to lowest.

join

CommandDescription
SELECT e.name, d.name FROM employees e JOIN departments d ON e.department_id = d.idList each employee's name alongside their department name.
SELECT o.id, e.name FROM orders o JOIN employees e ON o.employee_id = e.idList each order id with the name of the employee who placed it.
SELECT e.name FROM employees e JOIN departments d ON e.department_id = d.id WHERE d.name = 'Engineering'List the names of all employees in the Engineering department.
SELECT e.name, d.name FROM employees e LEFT JOIN departments d ON e.department_id = d.id ORDER BY e.idList every employee with their department name, ordered by employee id.
SELECT e.name, o.amount, o.status FROM orders o JOIN employees e ON o.employee_id = e.idList each order's employee name, amount, and status.

group

CommandDescription
SELECT department_id, COUNT(id) FROM employees GROUP BY department_id ORDER BY department_idCount employees in each department, ordered by department id.
SELECT employee_id, SUM(amount) FROM orders GROUP BY employee_id ORDER BY employee_idCalculate total order amount per employee, ordered by employee id.
SELECT status, COUNT(id) FROM orders GROUP BY status ORDER BY statusCount orders grouped by status, ordered alphabetically by status.
SELECT d.name, COUNT(e.id) FROM departments d JOIN employees e ON d.id = e.department_id GROUP BY d.name ORDER BY d.nameCount employees per department name, ordered alphabetically by department.
SELECT department_id, AVG(salary) FROM employees GROUP BY department_id ORDER BY department_idCalculate average salary per department, ordered by department id.

Key Use Cases

  • Filter employees with WHERE and compare null-safe predicates
  • Join employees to departments without duplicating rows by accident
  • Sort and limit result sets for a leaderboard-style query
  • GROUP BY with HAVING to keep only groups that meet a threshold
  • Compute COUNT, SUM, and AVG over orders in the sample schema

Frequently Asked Questions

Why does this track check query results instead of exact SQL text?

Equivalent SQL can be written many ways. The sandbox compares the result set so JOIN order and alias names are not a trap, while a wrong filter still fails.

What is the difference between WHERE and HAVING?

WHERE filters rows before grouping. HAVING filters groups after aggregation. Putting an aggregate in WHERE is invalid; this track tests that split.

INNER JOIN vs LEFT JOIN on this schema?

INNER JOIN drops employees without a matching department. LEFT JOIN keeps them with null department columns. Pick the join that matches the question's required rows.

Is this MySQL or PostgreSQL?

The prompts use portable SELECT/JOIN/GROUP BY on a tiny company database. Vendor-only functions are out of scope so the same query idea transfers.

Ready to master SQL commands?

Test your muscle memory with our spaced-repetition quiz system. Free forever.

Start Practice Now →