Bird
Raised Fist0
SQLquery~20 mins

SELECT specific columns in SQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Master of SELECT specific columns
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
Selecting specific columns from a table

Given a table Employees with columns id, name, department, and salary, what will be the output of this query?

SELECT name, salary FROM Employees;
SQL
CREATE TABLE Employees (id INT, name VARCHAR(50), department VARCHAR(50), salary INT);
INSERT INTO Employees VALUES (1, 'Alice', 'HR', 50000), (2, 'Bob', 'IT', 60000), (3, 'Charlie', 'Finance', 55000);
A[{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}, {"id": 3, "name": "Charlie"}]
B[{"name": "Alice", "salary": 50000}, {"name": "Bob", "salary": 60000}, {"name": "Charlie", "salary": 55000}]
C[{"department": "HR", "salary": 50000}, {"department": "IT", "salary": 60000}, {"department": "Finance", "salary": 55000}]
D[{"id": 1, "department": "HR"}, {"id": 2, "department": "IT"}, {"id": 3, "department": "Finance"}]
Attempts:
2 left
💡 Hint

Look at the columns listed after SELECT. Only those columns will appear in the output.

❓ query_result
intermediate
2:00remaining
Selecting columns with WHERE clause

What will be the output of this query on the Employees table?

SELECT id, name FROM Employees WHERE salary > 55000;
SQL
CREATE TABLE Employees (id INT, name VARCHAR(50), department VARCHAR(50), salary INT);
INSERT INTO Employees VALUES (1, 'Alice', 'HR', 50000), (2, 'Bob', 'IT', 60000), (3, 'Charlie', 'Finance', 55000);
A[{"id": 3, "name": "Charlie"}]
B[{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]
C[{"id": 2, "name": "Bob"}]
D[{"id": 2, "name": "Bob"}, {"id": 3, "name": "Charlie"}]
Attempts:
2 left
💡 Hint

Only rows where salary is greater than 55000 are included.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in selecting columns

Which option contains a syntax error when selecting specific columns from the Employees table?

ASELECT id name FROM Employees;
BSELECT id, name FROM Employees;
CSELECT name, salary FROM Employees;
DSELECT department FROM Employees;
Attempts:
2 left
💡 Hint

Check if commas separate the column names correctly.

❓ optimization
advanced
2:00remaining
Optimizing column selection for performance

You want to retrieve only the name and department columns from a large Employees table. Which query is best for performance?

ASELECT * FROM Employees;
BSELECT id, name, department FROM Employees;
CSELECT name, department, salary FROM Employees;
DSELECT name, department FROM Employees;
Attempts:
2 left
💡 Hint

Select only the columns you need to reduce data transfer.

🧠 Conceptual
expert
2:00remaining
Understanding column selection with aliases

Consider this query:

SELECT name AS employee_name, salary AS employee_salary FROM Employees;

What will be the column names in the output?

A["employee_name", "employee_salary"]
B["name AS employee_name", "salary AS employee_salary"]
C["name", "salary"]
D["employee", "salary"]
Attempts:
2 left
💡 Hint

Look at the AS keyword which renames columns in the output.

Practice

(1/5)
1. What does the SQL statement SELECT name, age FROM users; do?
easy
A. It retrieves all columns from the users table.
B. It updates the name and age columns in the users table.
C. It deletes the name and age columns from the users table.
D. It retrieves only the name and age columns from the users table.

Solution

  1. Step 1: Understand the SELECT clause

    The SELECT clause specifies which columns to retrieve from the table.
  2. Step 2: Identify columns listed

    The columns listed are name and age, so only these will be returned.
  3. Final Answer:

    It retrieves only the name and age columns from the users table. -> Option D
  4. Quick Check:

    SELECT specific columns = selected columns only [OK]
Hint: SELECT lists columns to get only those columns [OK]
Common Mistakes:
  • Thinking SELECT * returns specific columns
  • Confusing SELECT with DELETE or UPDATE
  • Not separating columns by commas
2. Which of the following is the correct syntax to select the columns 'id' and 'email' from a table named 'contacts'?
easy
A. SELECT id email FROM contacts;
B. SELECT id, email FROM contacts;
C. SELECT (id, email) FROM contacts;
D. SELECT id; email FROM contacts;

Solution

  1. Step 1: Check column separation syntax

    Columns must be separated by commas without parentheses.
  2. Step 2: Identify correct option

    SELECT id, email FROM contacts; uses commas correctly: SELECT id, email FROM contacts;
  3. Final Answer:

    SELECT id, email FROM contacts; -> Option B
  4. Quick Check:

    Columns separated by commas = correct syntax [OK]
Hint: Separate columns with commas, no parentheses [OK]
Common Mistakes:
  • Omitting commas between columns
  • Using parentheses around columns
  • Using semicolons between columns
3. Given the table products with columns product_id, name, and price, what will be the output of this query?
SELECT name, price FROM products WHERE price < 50;
medium
A. All columns for products priced below 50
B. An error because price is not selected
C. Only the name and price columns for products priced below 50
D. Only the product_id column for products priced below 50

Solution

  1. Step 1: Understand SELECT columns

    The query selects only name and price columns.
  2. Step 2: Apply WHERE condition

    Only rows where price is less than 50 are included.
  3. Final Answer:

    Only the name and price columns for products priced below 50 -> Option C
  4. Quick Check:

    SELECT specific columns + WHERE filters rows [OK]
Hint: SELECT columns limits output columns, WHERE filters rows [OK]
Common Mistakes:
  • Expecting all columns to be returned
  • Thinking WHERE changes columns selected
  • Assuming error if column not in SELECT
4. Identify the error in this SQL query:
SELECT name age FROM employees;
medium
A. Missing comma between columns name and age
B. Table name employees is incorrect
C. SELECT cannot be used without WHERE
D. No error, query is correct

Solution

  1. Step 1: Check column separation

    Columns must be separated by commas; here name and age are not separated.
  2. Step 2: Confirm table name and syntax

    Table name employees is valid and WHERE is optional.
  3. Final Answer:

    Missing comma between columns name and age -> Option A
  4. Quick Check:

    Columns need commas between them [OK]
Hint: Always separate columns with commas [OK]
Common Mistakes:
  • Forgetting commas between columns
  • Thinking WHERE is mandatory
  • Assuming table name is wrong without evidence
5. You have a table orders with columns order_id, customer_id, order_date, and total. You want to list only the order_id and total for orders made in 2023. Which query is correct?
hard
A. SELECT order_id, total FROM orders WHERE order_date LIKE '2023%';
B. SELECT order_id total FROM orders WHERE order_date = 2023;
C. SELECT order_id, total FROM orders WHERE order_date = '2023';
D. SELECT * FROM orders WHERE order_date LIKE '2023%';

Solution

  1. Step 1: Select specific columns

    We want only order_id and total, so SELECT order_id, total is correct.
  2. Step 2: Filter orders from 2023

    Using WHERE order_date LIKE '2023%' matches dates starting with 2023.
  3. Step 3: Check other options

    SELECT order_id total FROM orders WHERE order_date = 2023; misses comma and uses wrong date filter; SELECT order_id, total FROM orders WHERE order_date = '2023'; uses exact match which won't work for full dates; SELECT * FROM orders WHERE order_date LIKE '2023%'; selects all columns, not specific ones.
  4. Final Answer:

    SELECT order_id, total FROM orders WHERE order_date LIKE '2023%'; -> Option A
  5. Quick Check:

    Select columns + LIKE filter for year = correct query [OK]
Hint: Use LIKE '2023%' to filter year, separate columns with commas [OK]
Common Mistakes:
  • Forgetting commas between columns
  • Using = instead of LIKE for partial date match
  • Selecting all columns instead of specific ones
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