0
0
MySQLquery~20 mins

First query execution in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
First Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this simple SELECT query?
Consider a table employees with columns id and name. The table has 3 rows:
1, 'Alice'
2, 'Bob'
3, 'Charlie'

What will be the result of this query?
SELECT name FROM employees WHERE id = 2;
MySQL
SELECT name FROM employees WHERE id = 2;
A[]
B[{"name": "Bob"}]
C[{"name": "Alice"}]
D[{"id": 2}]
Attempts:
2 left
💡 Hint
Look for the row where the id is exactly 2.
📝 Syntax
intermediate
2:00remaining
Which query will cause a syntax error?
Identify which of the following MySQL queries will cause a syntax error when executed.
ASELECT * FROM employees WHERE id = 1;
BSELECT COUNT(*) FROM employees;
CSELECT id, name FROM employees;
DSELECT name FROM employees WHERE id == 1;
Attempts:
2 left
💡 Hint
MySQL uses a single equals sign for comparison.
query_result
advanced
2:30remaining
What is the output of this aggregate query?
Given the sales table with columns product and amount containing:
('apple', 10), ('banana', 5), ('apple', 15), ('banana', 10)

What is the result of this query?
SELECT product, SUM(amount) AS total FROM sales GROUP BY product ORDER BY total DESC;
MySQL
SELECT product, SUM(amount) AS total FROM sales GROUP BY product ORDER BY total DESC;
A[{"product": "apple", "total": 10}, {"product": "banana", "total": 5}]
B[{"product": "banana", "total": 15}, {"product": "apple", "total": 25}]
C[{"product": "apple", "total": 25}, {"product": "banana", "total": 15}]
D[{"product": "apple", "total": 15}, {"product": "banana", "total": 10}]
Attempts:
2 left
💡 Hint
SUM adds amounts per product, ORDER BY sorts descending by total.
🔧 Debug
advanced
2:30remaining
Why does this query return no rows?
Given a table users with a column username containing 'alice', 'bob', 'charlie', why does this query return no rows?
SELECT * FROM users WHERE username = 'Alice';
ABecause the username 'Alice' does not exist exactly with uppercase A.
BBecause the query syntax is incorrect.
CBecause MySQL string comparison is case-sensitive by default.
DBecause the users table is empty.
Attempts:
2 left
💡 Hint
Check the exact spelling and case of usernames in the table.
optimization
expert
3:00remaining
Which query is more efficient for counting rows?
You want to count how many rows are in the orders table. Which query is more efficient in MySQL?
ASELECT COUNT(*) FROM orders;
BSELECT COUNT(1) FROM orders;
CSELECT COUNT(order_id) FROM orders;
DSELECT COUNT('order_id') FROM orders;
Attempts:
2 left
💡 Hint
COUNT(*) counts all rows regardless of NULLs.