0
0
SQLquery~20 mins

How the database engine processes a SELECT in SQL - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of SELECT Processing
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of SELECT with WHERE and ORDER BY
Given the table Employees with columns id, name, and salary, what is the output of this query?
SELECT name FROM Employees WHERE salary > 50000 ORDER BY name ASC;
SQL
CREATE TABLE Employees (id INT, name VARCHAR(50), salary INT);
INSERT INTO Employees VALUES (1, 'Alice', 60000), (2, 'Bob', 45000), (3, 'Charlie', 70000);
SELECT name FROM Employees WHERE salary > 50000 ORDER BY name ASC;
A[{"name": "Alice"}, {"name": "Charlie"}]
B[{"name": "Charlie"}, {"name": "Alice"}]
C[{"name": "Bob"}]
D[]
Attempts:
2 left
💡 Hint
Think about filtering first, then sorting alphabetically.
🧠 Conceptual
intermediate
2:00remaining
Order of operations in SELECT processing
In what order does the database engine process the clauses in a SELECT statement?
A1,2,3,4,5,6
B5,1,2,3,4,6
C1,5,2,3,4,6
D2,1,3,5,4,6
Attempts:
2 left
💡 Hint
Think about which clause filters rows first and which one selects columns.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this SELECT query
Which option contains a syntax error when trying to select all columns from Products where price is less than 100?
ASELECT * FROM Products WHERE price < 100 ORDER BY;
BSELECT * Products WHERE price < 100;
CSELECT * FROM Products WHERE price < 100;
DSELECT * FROM Products WHERE price < 100
Attempts:
2 left
💡 Hint
Check the FROM clause syntax carefully.
optimization
advanced
2:00remaining
Optimizing SELECT with JOIN and WHERE
Given two tables Orders and Customers, which query is more efficient to find orders from customers in 'New York'?
ASELECT o.id FROM Orders o WHERE EXISTS (SELECT 1 FROM Customers c WHERE c.id = o.customer_id AND c.city = 'New York');
BSELECT o.id FROM Orders o, Customers c WHERE o.customer_id = c.id AND c.city = 'New York';
CSELECT o.id FROM Orders o WHERE o.customer_id IN (SELECT id FROM Customers WHERE city = 'New York');
DSELECT o.id FROM Orders o JOIN Customers c ON o.customer_id = c.id WHERE c.city = 'New York';
Attempts:
2 left
💡 Hint
Consider how JOINs and subqueries affect query planning.
🔧 Debug
expert
2:00remaining
Why does this SELECT query return no rows?
Consider these tables:
Users(id, name)
Orders(id, user_id, total)

Why does this query return no rows?
SELECT u.name FROM Users u LEFT JOIN Orders o ON u.id = o.user_id WHERE o.total > 100;
ABecause the ON condition is incorrect and causes no matches.
BBecause LEFT JOIN only returns rows with matching orders, so no users without orders appear.
CBecause the WHERE clause filters out rows where o.total is NULL, removing all users without orders.
DBecause the SELECT clause is missing a GROUP BY for aggregation.
Attempts:
2 left
💡 Hint
Think about how WHERE affects rows after a LEFT JOIN.