0
0
MySQLquery~20 mins

MySQL CLI and Workbench - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MySQL CLI and Workbench Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of a SELECT query with WHERE clause in MySQL CLI
Consider a table employees with columns id, name, and department. What is the output of the following query executed in MySQL CLI?
SELECT name FROM employees WHERE department = 'Sales';
MySQL
SELECT name FROM employees WHERE department = 'Sales';
A[{"name": "Alice"}, {"name": "Charlie"}]
B[{"name": "Alice"}, {"name": "Bob"}]
C[{"id": 1, "name": "Alice"}, {"id": 3, "name": "Bob"}]
DSyntaxError
Attempts:
2 left
💡 Hint
Focus on the SELECT columns and the WHERE condition filtering by department.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in a MySQL Workbench query
Which option contains a syntax error when run in MySQL Workbench?
SELECT * FROM orders WHERE order_date = '2023-01-01'
MySQL
SELECT * FROM orders WHERE order_date = '2023-01-01'
ASELECT * orders WHERE order_date = '2023-01-01';
BSELECT * FROM orders WHERE order_date = '2023-01-01'
CSELECT * FROM orders WHERE order_date = '2023-01-01';
D;'10-10-3202' = etad_redro EREHW sredro MORF * TCELES
Attempts:
2 left
💡 Hint
Check the FROM clause syntax carefully.
optimization
advanced
2:00remaining
Optimizing a slow query in MySQL CLI
You have a large table sales with millions of rows. The query below is slow:
SELECT * FROM sales WHERE customer_id = 12345;

Which option will most improve query speed when run in MySQL CLI?
MySQL
SELECT * FROM sales WHERE customer_id = 12345;
AAdd an index on the customer_id column.
BRewrite the query as SELECT * FROM sales;
CUse ORDER BY customer_id DESC in the query.
DIncrease the LIMIT to 10000 rows.
Attempts:
2 left
💡 Hint
Indexes help MySQL find rows faster when filtering.
🔧 Debug
advanced
2:00remaining
Debugging connection error in MySQL Workbench
You try to connect to a MySQL server in Workbench but get the error:
"Can't connect to MySQL server on 'localhost' (10061)"
Which option is the most likely cause?
AThe table name is misspelled in the query.
BThe SQL query syntax is incorrect.
CMySQL server is not running on localhost.
DThe SELECT statement is missing a semicolon.
Attempts:
2 left
💡 Hint
Connection errors usually relate to server availability or network.
🧠 Conceptual
expert
2:00remaining
Understanding transaction behavior in MySQL CLI
In MySQL CLI, you start a transaction with START TRANSACTION; and run:
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;

But you forget to run COMMIT; and close the CLI. What happens to the changes?
AAll changes are saved automatically despite missing COMMIT.
BThe database throws an error and keeps partial changes.
COnly the first UPDATE is saved, the second is lost.
DAll changes are rolled back and not saved to the database.
Attempts:
2 left
💡 Hint
Think about what happens to uncommitted transactions when the session ends.