Bird
Raised Fist0
SQLquery~20 mins

Tables, rows, and columns concept in SQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Tables Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
Identify the number of rows returned
Given the table Employees with columns id, name, and department, what is the number of rows returned by this query?
SELECT * FROM Employees WHERE department = 'Sales';
SQL
SELECT * FROM Employees WHERE department = 'Sales';
A0
B5
C3
D7
Attempts:
2 left
💡 Hint
Think about how many employees belong to the Sales department.
🧠 Conceptual
intermediate
1:30remaining
Understanding columns in a table
Which of the following best describes a column in a database table?
AA single record containing all data about one entity
BA temporary storage area for query results
CA horizontal set of data values representing multiple entities
DA vertical set of data values representing a specific attribute
Attempts:
2 left
💡 Hint
Think about how data is organized vertically in tables.
📝 Syntax
advanced
2:00remaining
Identify the correct SQL syntax to select specific columns
Which SQL query correctly selects only the name and department columns from the Employees table?
ASELECT name, department FROM Employees;
BSELECT * FROM Employees WHERE name, department;
CSELECT name & department FROM Employees;
DSELECT name department FROM Employees;
Attempts:
2 left
💡 Hint
Remember the syntax for selecting multiple columns uses commas.
🔧 Debug
advanced
2:00remaining
Find the error in this SQL query
What error will this SQL query produce?
SELECT id, name, department FROM Employees WHERE department = Sales;
ASyntax error due to missing quotes around 'Sales'
BNo error, query runs successfully
CRuntime error due to missing table Employees
DSyntax error due to missing comma between columns
Attempts:
2 left
💡 Hint
String values in SQL must be enclosed in quotes.
❓ optimization
expert
2:30remaining
Optimize query to count rows efficiently
Which query is the most efficient way to count the number of employees in the Employees table?
ASELECT COUNT(id, name) FROM Employees;
BSELECT COUNT(*) FROM Employees;
CSELECT * FROM Employees; -- then count rows in application
DSELECT COUNT(department) FROM Employees WHERE department IS NOT NULL;
Attempts:
2 left
💡 Hint
Use SQL aggregate functions designed for counting rows.

Practice

(1/5)
1. What does a row represent in a database table?
easy
A. A group of tables linked together
B. The name of the table
C. The type of data stored in the table
D. A single record containing data for each column

Solution

  1. Step 1: Understand the structure of a table

    A table is made up of rows and columns where columns define data types and rows hold data.
  2. Step 2: Identify what a row represents

    A row is one complete record with values for each column in the table.
  3. Final Answer:

    A single record containing data for each column -> Option D
  4. Quick Check:

    Row = single record [OK]
Hint: Rows = records, columns = data types [OK]
Common Mistakes:
  • Confusing rows with columns
  • Thinking rows are table names
  • Mixing up rows with database schemas
2. Which of the following is the correct way to select all columns from a table named Employees?
easy
A. GET * FROM Employees;
B. SELECT ALL COLUMNS Employees;
C. SELECT * FROM Employees;
D. SELECT COLUMNS FROM Employees;

Solution

  1. Step 1: Recall SQL syntax for selecting all columns

    The standard SQL command to select all columns is SELECT * FROM table_name;.
  2. Step 2: Match the correct syntax

    SELECT * FROM Employees; matches the correct syntax exactly.
  3. Final Answer:

    SELECT * FROM Employees; -> Option C
  4. Quick Check:

    SELECT * = all columns [OK]
Hint: Use * to select all columns [OK]
Common Mistakes:
  • Using GET instead of SELECT
  • Writing SELECT ALL COLUMNS which is invalid
  • Omitting FROM keyword
3. Given the table Students with columns id, name, and age, what will this query return?
SELECT name FROM Students WHERE age > 20;
medium
A. Only the names of students older than 20
B. All columns for students older than 20
C. Only the ages of students older than 20
D. An error because age is not selected

Solution

  1. Step 1: Analyze the SELECT clause

    The query selects only the name column from the table.
  2. Step 2: Analyze the WHERE condition

    It filters rows where age is greater than 20, so only those students are included.
  3. Final Answer:

    Only the names of students older than 20 -> Option A
  4. Quick Check:

    SELECT name WHERE age > 20 = names only [OK]
Hint: SELECT columns control output, WHERE filters rows [OK]
Common Mistakes:
  • Thinking all columns are returned
  • Assuming age column is returned without selecting it
  • Believing query causes error due to WHERE clause
4. What is wrong with this SQL query?
SELECT id, name FROM Students WHERE age = 'twenty';
medium
A. Using quotes around a number in WHERE clause causes error
B. Comparing age to a string 'twenty' may cause no matches
C. Selecting multiple columns requires commas
D. Missing FROM keyword before table name

Solution

  1. Step 1: Check the WHERE clause comparison

    The query compares age to the string 'twenty', but age is numeric.
  2. Step 2: Understand effect of comparing number to string

    This will not cause a syntax error but likely returns zero rows because no numeric age equals 'twenty'.
  3. Final Answer:

    Comparing age to a string 'twenty' may cause no matches -> Option B
  4. Quick Check:

    Wrong data type comparison = no results [OK]
Hint: Match data types in WHERE clause [OK]
Common Mistakes:
  • Thinking quotes cause syntax error
  • Assuming query returns matching rows
  • Ignoring data type mismatch
5. You have a table Orders with columns order_id, customer_id, and amount. You want to find the total amount spent by each customer. Which SQL query correctly groups and sums the data?
hard
A. SELECT customer_id, SUM(amount) FROM Orders GROUP BY customer_id;
B. SELECT order_id, SUM(amount) FROM Orders GROUP BY order_id;
C. SELECT customer_id, amount FROM Orders WHERE SUM(amount) > 100;
D. SELECT customer_id, amount FROM Orders GROUP BY amount;

Solution

  1. Step 1: Identify the goal

    We want total amount spent per customer, so we must group by customer_id.
  2. Step 2: Use aggregation function

    SUM(amount) calculates total amount per group.
  3. Step 3: Check query correctness

    SELECT customer_id, SUM(amount) FROM Orders GROUP BY customer_id; correctly groups by customer_id and sums amount.
  4. Final Answer:

    SELECT customer_id, SUM(amount) FROM Orders GROUP BY customer_id; -> Option A
  5. Quick Check:

    Group by customer_id + SUM(amount) = total per customer [OK]
Hint: Group by key, aggregate values with SUM [OK]
Common Mistakes:
  • Grouping by wrong column
  • Using WHERE with aggregate functions incorrectly
  • Selecting columns not in GROUP BY without aggregation
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