Bird
Raised Fist0
MySQLquery~20 mins

First query execution in MySQL - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What does the SELECT statement do in MySQL?
easy
A. It retrieves data from a database table.
B. It deletes data from a database table.
C. It updates data in a database table.
D. It creates a new database table.

Solution

  1. Step 1: Understand the purpose of SELECT

    The SELECT statement is used to get or read data from a table in a database.
  2. Step 2: Compare with other SQL commands

    DELETE removes data, UPDATE changes data, and CREATE makes new tables, so they are different from SELECT.
  3. Final Answer:

    It retrieves data from a database table. -> Option A
  4. Quick Check:

    SELECT = retrieve data [OK]
Hint: SELECT means get data from a table [OK]
Common Mistakes:
  • Confusing SELECT with DELETE or UPDATE
  • Thinking SELECT creates tables
  • Mixing SELECT with data modification commands
2. Which of the following is the correct syntax to select all columns from a table named users?
easy
A. SELECT users FROM *;
B. SELECT * FROM users;
C. SELECT * users FROM;
D. FROM users SELECT *;

Solution

  1. Step 1: Recall the basic SELECT syntax

    The correct syntax to get all columns is: SELECT * FROM table_name;
  2. Step 2: Check each option

    SELECT * FROM users; matches the correct syntax. Others have wrong order or misplaced keywords.
  3. Final Answer:

    SELECT * FROM users; -> Option B
  4. Quick Check:

    SELECT * FROM table_name; is correct [OK]
Hint: SELECT * FROM table_name; gets all columns [OK]
Common Mistakes:
  • Swapping SELECT and FROM keywords
  • Omitting the FROM keyword
  • Placing * in wrong position
3. Given a table products with columns id, name, and price, what will this query return?
SELECT name FROM products;
medium
A. All product names from the products table.
B. All product prices from the products table.
C. All columns from the products table.
D. An error because price column is missing.

Solution

  1. Step 1: Understand the SELECT clause

    The query selects only the 'name' column from the products table.
  2. Step 2: Check what is returned

    It returns all rows but only the 'name' column values, not price or id.
  3. Final Answer:

    All product names from the products table. -> Option A
  4. Quick Check:

    SELECT name returns names only [OK]
Hint: SELECT column_name returns that column's data [OK]
Common Mistakes:
  • Assuming all columns are returned
  • Thinking missing columns cause errors
  • Confusing column names in SELECT
4. What is wrong with this query?
SELECT FROM users;
medium
A. FROM keyword should be after WHERE.
B. Table name is incorrect.
C. Missing column names or * after SELECT.
D. SELECT cannot be used with FROM.

Solution

  1. Step 1: Check the SELECT syntax

    SELECT must be followed by column names or * to specify what to retrieve.
  2. Step 2: Identify the error in the query

    The query has SELECT but no columns or * after it, causing a syntax error.
  3. Final Answer:

    Missing column names or * after SELECT. -> Option C
  4. Quick Check:

    SELECT needs columns or * [OK]
Hint: Always specify columns or * after SELECT [OK]
Common Mistakes:
  • Leaving SELECT empty
  • Misplacing FROM keyword
  • Thinking FROM is optional
5. You want to see all columns from a table employees but only for employees with the job title 'Manager'. Which query should you use?
hard
A. SELECT * WHERE job_title = 'Manager' FROM employees;
B. SELECT job_title FROM employees WHERE job_title = 'Manager';
C. SELECT * FROM employees;
D. SELECT * FROM employees WHERE job_title = 'Manager';

Solution

  1. Step 1: Identify the need to filter rows

    We want all columns but only rows where job_title is 'Manager', so we need a WHERE clause.
  2. Step 2: Check query syntax and logic

    SELECT * FROM employees WHERE job_title = 'Manager'; correctly uses SELECT * FROM employees WHERE job_title = 'Manager'; which returns all columns filtered by job title.
  3. Final Answer:

    SELECT * FROM employees WHERE job_title = 'Manager'; -> Option D
  4. Quick Check:

    Use WHERE to filter rows [OK]
Hint: Use WHERE to filter rows after FROM [OK]
Common Mistakes:
  • Omitting WHERE clause for filtering
  • Placing WHERE before FROM
  • Selecting only job_title instead of all columns
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard