0
0
SQLquery~20 mins

Relational model mental model in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Relational Model 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 SQL query on a simple employee table?

Consider a table Employees with columns id, name, and department. The table has these rows:

  • (1, 'Alice', 'HR')
  • (2, 'Bob', 'IT')
  • (3, 'Charlie', 'IT')

What is the result of this query?

SELECT department, COUNT(*) AS count FROM Employees GROUP BY department;
SQL
SELECT department, COUNT(*) AS count FROM Employees GROUP BY department;
A[{"department": "HR", "count": 1}, {"department": "IT", "count": 2}]
B[{"department": "HR", "count": 2}, {"department": "IT", "count": 1}]
C[{"department": "HR", "count": 3}]
D[{"department": "IT", "count": 3}]
Attempts:
2 left
💡 Hint

Grouping counts how many rows share the same department.

🧠 Conceptual
intermediate
1:30remaining
Which statement best describes a primary key in the relational model?

In the relational model, what is the main purpose of a primary key in a table?

AIt allows duplicate values in a column.
BIt defines the order in which rows are stored.
CIt stores the largest value in a column.
DIt uniquely identifies each row in the table.
Attempts:
2 left
💡 Hint

Think about how you find one specific record in a table.

📝 Syntax
advanced
2:00remaining
Which SQL query correctly finds employees with no department assigned?

Given a table Employees with a nullable department column, which query correctly returns employees where department is not assigned?

ASELECT * FROM Employees WHERE department IS NULL;
BSELECT * FROM Employees WHERE department = 'NULL';
CSELECT * FROM Employees WHERE department = NULL;
DSELECT * FROM Employees WHERE department != NULL;
Attempts:
2 left
💡 Hint

Remember how SQL treats NULL comparisons.

optimization
advanced
2:30remaining
Which index improves performance for this query on a large table?

Consider a large Orders table with columns order_id, customer_id, and order_date. You run this query often:

SELECT * FROM Orders WHERE customer_id = 12345;

Which index will improve query speed the most?

ACREATE INDEX idx_order_date ON Orders(order_date);
BCREATE INDEX idx_customer_id ON Orders(customer_id);
CCREATE INDEX idx_order_id ON Orders(order_id);
DCREATE INDEX idx_customer_order ON Orders(customer_id, order_date);
Attempts:
2 left
💡 Hint

Think about which column is used in the WHERE clause.

🔧 Debug
expert
3:00remaining
Why does this SQL query return zero rows?

Given tables Students(id, name) and Enrollments(student_id, course_id), this query returns no rows:

SELECT s.name FROM Students s JOIN Enrollments e ON s.id = e.student_id WHERE e.course_id = 101;

What is the most likely reason?

AThe WHERE clause should be on Students table, not Enrollments.
BThe JOIN condition is incorrect; it should be ON s.id = e.course_id.
CThere are no students enrolled in course 101.
DThe query needs a GROUP BY clause to return results.
Attempts:
2 left
💡 Hint

Check if any rows match the filter condition.