Bird
Raised Fist0
SQLquery~20 mins

Single column index in SQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Single Column Index Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
Effect of Single Column Index on Query Performance

Consider a table Employees with columns id, name, and department. A single column index is created on the department column.

What will be the output of the following query?

SELECT name FROM Employees WHERE department = 'Sales';

Assume the table has these rows:

id | name   | department
1  | Alice  | Sales
2  | Bob    | HR
3  | Carol  | Sales
4  | Dave   | IT
SQL
SELECT name FROM Employees WHERE department = 'Sales';
A["Alice", "Carol"]
B["Alice", "Bob", "Carol", "Dave"]
C[]
D["Bob", "Dave"]
Attempts:
2 left
💡 Hint

Think about which rows match the condition department = 'Sales'.

🧠 Conceptual
intermediate
1:30remaining
Purpose of Single Column Index

What is the main purpose of creating a single column index on a database table?

ATo automatically backup the table data
BTo speed up queries filtering or sorting by that column
CTo prevent any data from being inserted into that column
DTo store duplicate values in the column
Attempts:
2 left
💡 Hint

Think about how indexes help when searching data.

📝 Syntax
advanced
1:30remaining
Correct Syntax to Create Single Column Index

Which SQL statement correctly creates a single column index named idx_department on the department column of the Employees table?

AINDEX CREATE idx_department ON Employees(department);
BCREATE INDEX ON Employees idx_department(department);
CCREATE Employees INDEX idx_department ON department;
DCREATE INDEX idx_department ON Employees(department);
Attempts:
2 left
💡 Hint

Remember the order: CREATE INDEX index_name ON table(column);

❓ optimization
advanced
2:00remaining
Query Optimization Using Single Column Index

Given a large Orders table with millions of rows, which query will benefit most from a single column index on the customer_id column?

ASELECT * FROM Orders WHERE customer_id = 12345;
BSELECT * FROM Orders WHERE order_date = '2023-01-01';
CSELECT COUNT(*) FROM Orders;
DSELECT * FROM Orders ORDER BY order_date;
Attempts:
2 left
💡 Hint

Indexes help when filtering by the indexed column.

🔧 Debug
expert
2:30remaining
Why Does This Query Not Use the Single Column Index?

Consider a single column index on department in the Employees table. Why does this query not use the index?

SELECT * FROM Employees WHERE UPPER(department) = 'SALES';
ABecause the query is missing a JOIN clause
BBecause the index only works with numeric columns
CBecause the function <code>UPPER()</code> on the column prevents index usage
DBecause the table has no rows
Attempts:
2 left
💡 Hint

Think about how functions on indexed columns affect index use.

Practice

(1/5)
1.

What is the main purpose of creating a single column index in a database?

easy
A. To store duplicate values in the column
B. To automatically backup the database
C. To prevent any changes to the column data
D. To speed up queries that filter or sort by that column

Solution

  1. Step 1: Understand what an index does

    An index helps the database find rows faster when searching or sorting by the indexed column.
  2. Step 2: Identify the purpose of a single column index

    A single column index speeds up queries that use that column in WHERE or ORDER BY clauses.
  3. Final Answer:

    To speed up queries that filter or sort by that column -> Option D
  4. Quick Check:

    Index speeds up queries = B [OK]
Hint: Index speeds up searches on one column [OK]
Common Mistakes:
  • Thinking index stores duplicate values
  • Believing index prevents data changes
  • Confusing index with backup
2.

Which of the following is the correct syntax to create a single column index on the email column of a table named users?

easy
A. CREATE INDEX users ON idx_email(email);
B. CREATE INDEX idx_email ON users(email);
C. CREATE INDEX email ON users idx_email;
D. CREATE users INDEX idx_email(email);

Solution

  1. Step 1: Recall the syntax for creating an index

    The correct syntax is: CREATE INDEX index_name ON table_name(column_name);
  2. Step 2: Match the syntax with the options

    CREATE INDEX idx_email ON users(email); matches the correct syntax exactly.
  3. Final Answer:

    CREATE INDEX idx_email ON users(email); -> Option B
  4. Quick Check:

    CREATE INDEX index_name ON table(column) = A [OK]
Hint: Syntax: CREATE INDEX name ON table(column) [OK]
Common Mistakes:
  • Swapping table and index names
  • Missing ON keyword
  • Incorrect order of keywords
3.

Given a table products with columns id, name, and category, and a single column index on category, what will the query below most likely do?

SELECT * FROM products WHERE category = 'Books';
medium
A. Use the index to quickly find rows where category is 'Books'
B. Sort the results by category before returning
C. Return an error because index cannot be used in WHERE clause
D. Scan the entire table without using the index

Solution

  1. Step 1: Understand how an index affects a WHERE query

    An index on the category column helps the database quickly locate rows matching the condition category = 'Books'.
  2. Step 2: Analyze the query behavior with the index

    The query will use the index to avoid scanning the whole table, speeding up the search.
  3. Final Answer:

    Use the index to quickly find rows where category is 'Books' -> Option A
  4. Quick Check:

    Index speeds WHERE search = D [OK]
Hint: WHERE on indexed column uses index for speed [OK]
Common Mistakes:
  • Assuming index is ignored in WHERE clause
  • Thinking index causes errors in queries
  • Confusing index use with sorting
4.

Consider this SQL statement to create an index:

CREATE INDEX idx_price ON products price;

What is wrong with this statement?

medium
A. Table name should come after the column name
B. Index name cannot start with 'idx_'
C. Missing parentheses around the column name
D. CREATE INDEX cannot be used on numeric columns

Solution

  1. Step 1: Check the syntax for CREATE INDEX

    The column name must be inside parentheses after the table name.
  2. Step 2: Identify the syntax error

    The statement is missing parentheses around price. It should be ON products(price).
  3. Final Answer:

    Missing parentheses around the column name -> Option C
  4. Quick Check:

    Column name needs parentheses = C [OK]
Hint: Column name must be in parentheses after table [OK]
Common Mistakes:
  • Omitting parentheses around column
  • Misplacing table and column names
  • Thinking index names have restrictions
5.

You have a table orders with columns order_id, customer_id, and order_date. You want to speed up queries that filter by customer_id and sort by order_date. Which approach is best?

hard
A. Create a composite index on customer_id and order_date
B. Create a single column index on order_date only
C. Create a single column index on customer_id only
D. Create no index to avoid slowing down inserts

Solution

  1. Step 1: Understand query needs

    Queries filter by customer_id and sort by order_date, so both columns matter.
  2. Step 2: Choose the best index type

    A composite index on both columns helps filter and sort efficiently, better than single column indexes.
  3. Final Answer:

    Create a composite index on customer_id and order_date -> Option A
  4. Quick Check:

    Composite index for filter + sort = A [OK]
Hint: Use composite index for multiple column queries [OK]
Common Mistakes:
  • Using single column index when composite is better
  • Avoiding indexes fearing insert slowdown
  • Indexing only sort column ignoring filter
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