Challenge - 5 Problems
View Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Understanding View Update Restrictions
Which of the following is a common limitation when trying to update data through a MySQL view?
Attempts:
2 left
💡 Hint
Think about how aggregation affects the ability to identify individual rows.
✗ Incorrect
Views that use GROUP BY aggregate rows, so MySQL cannot determine which underlying rows to update.
❓ query_result
intermediate2:00remaining
Result of Selecting from a View with a Join
Given two tables employees and departments, and a view defined as:
What will be the output of
CREATE VIEW emp_dept AS SELECT e.id, e.name, d.name AS dept_name FROM employees e JOIN departments d ON e.dept_id = d.id;
What will be the output of
SELECT * FROM emp_dept WHERE dept_name = 'Sales';?MySQL
CREATE TABLE employees (id INT, name VARCHAR(20), dept_id INT); CREATE TABLE departments (id INT, name VARCHAR(20)); INSERT INTO employees VALUES (1, 'Alice', 10), (2, 'Bob', 20), (3, 'Carol', 10); INSERT INTO departments VALUES (10, 'Sales'), (20, 'HR'); CREATE VIEW emp_dept AS SELECT e.id, e.name, d.name AS dept_name FROM employees e JOIN departments d ON e.dept_id = d.id; SELECT * FROM emp_dept WHERE dept_name = 'Sales';
Attempts:
2 left
💡 Hint
Check which employees belong to the Sales department by matching dept_id.
✗ Incorrect
The view joins employees with departments. Employees with dept_id 10 belong to Sales, so Alice and Carol appear.
📝 Syntax
advanced2:00remaining
Identifying Invalid View Definition
Which of the following CREATE VIEW statements will cause a syntax error in MySQL?
Attempts:
2 left
💡 Hint
MySQL views do not allow ORDER BY without LIMIT.
✗ Incorrect
MySQL does not allow ORDER BY in view definitions unless combined with LIMIT.
❓ optimization
advanced2:00remaining
Performance Impact of Views with Subqueries
Consider a view defined with a subquery that calculates the average salary per department. Which of the following statements about performance is true?
Attempts:
2 left
💡 Hint
Think about how views behave internally in MySQL.
✗ Incorrect
MySQL views are virtual tables; subqueries inside them execute each time the view is queried, which can slow down performance.
🔧 Debug
expert2:00remaining
Diagnosing an Error When Updating a View
You have a view defined as:
When you try to run
CREATE VIEW v AS SELECT id, name, salary * 1.1 AS increased_salary FROM employees;
When you try to run
UPDATE v SET increased_salary = 5000 WHERE id = 1;, you get an error. What is the cause?Attempts:
2 left
💡 Hint
Think about what parts of a view can be updated.
✗ Incorrect
Views with calculated columns cannot be updated because MySQL cannot map the update back to the base table column.