Question & tables Return employee and manager names for employees with a manager, ordered by employee id.
30:00
Start / resume mock Question Finish and review Database schema customers(id, name, country)
orders(id, customer_id, ordered_at, amount, status)
employees(id, name, department, salary, manager_id)
events(id, user_id, event_date, event_type)
products(id, name, category, price, stock) orders.customer_id → customers.id employees.manager_id → employees.id events.user_id is a separate product-user identifier.
All data is synthetic. Dates use YYYY-MM-DD; unknown values are NULL.
Concept hint If a customer has three orders, that customer appears three times in a join. Another one-to-many table can multiply orders again. Aggregate each fact table to its intended grain before combining totals.
Reference solution & explanation SELECT e.name AS employee,m.name AS manager FROM employees e JOIN employees m ON m.id=e.manager_id ORDER BY e.id;INNER JOIN drops unmatched records; LEFT JOIN preserves the left side. Count the right-side primary key to obtain zero for unmatched rows. COUNT(*) would count the placeholder. Put the right-side status filter in ON when non-buyers must remain.
The checker compares output columns, values and requested row order across two fixture variants. Different SQL that produces the same results is accepted. This is a learning aid, not a proof of correctness on every possible dataset.
Read the topic guide → Your SQL query Ctrl / Cmd + Enter to run Run query Check answer Stop Reset query Save draft Download SQL
Loading the SQL engine…
Queries run locally, with an eight-second execution limit and a 500-row result limit. Signed-in learners can save exercise queries to their academy account. Practice results never change course grades or certificates.
This workspace needs JavaScript and WebAssembly. You can still read the question and reference solution.