0
0
MySQLquery~20 mins

View limitations in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
View Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding View Update Restrictions
Which of the following is a common limitation when trying to update data through a MySQL view?
AYou cannot update a view if it has no WHERE clause.
BYou cannot update a view if it is created with the SELECT * syntax.
CYou cannot update a view if it contains a GROUP BY clause.
DYou cannot update a view if it references only one table.
Attempts:
2 left
💡 Hint
Think about how aggregation affects the ability to identify individual rows.
query_result
intermediate
2:00remaining
Result of Selecting from a View with a Join
Given two tables employees and departments, and a view defined as:
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';
A[{id: 1, name: 'Alice', dept_name: 'Sales'}, {id: 3, name: 'Carol', dept_name: 'Sales'}]
B[{id: 2, name: 'Bob', dept_name: 'Sales'}]
C[]
D[{id: 1, name: 'Alice', dept_name: 'HR'}, {id: 3, name: 'Carol', dept_name: 'HR'}]
Attempts:
2 left
💡 Hint
Check which employees belong to the Sales department by matching dept_id.
📝 Syntax
advanced
2:00remaining
Identifying Invalid View Definition
Which of the following CREATE VIEW statements will cause a syntax error in MySQL?
ACREATE VIEW v AS SELECT id, name FROM users GROUP BY id;
BCREATE VIEW v AS SELECT id, name FROM users WHERE id > 10;
CCREATE VIEW v AS SELECT id, name FROM users WHERE name LIKE 'A%';
DCREATE VIEW v AS SELECT id, name FROM users ORDER BY name;
Attempts:
2 left
💡 Hint
MySQL views do not allow ORDER BY without LIMIT.
optimization
advanced
2: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?
AViews are virtual and subqueries inside them run every time the view is queried, potentially slowing performance.
BViews with subqueries are optimized by MySQL to run subqueries only once per query.
CViews always store data physically, so subqueries run only once.
DViews with subqueries automatically create indexes to speed up queries.
Attempts:
2 left
💡 Hint
Think about how views behave internally in MySQL.
🔧 Debug
expert
2:00remaining
Diagnosing an Error When Updating a View
You have a view defined as:
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?
AYou cannot update a view without a WHERE clause.
BYou cannot update a view that contains calculated columns like salary * 1.1.
CYou must use the base table name in the UPDATE statement, not the view name.
DThe view must include all columns from the base table to allow updates.
Attempts:
2 left
💡 Hint
Think about what parts of a view can be updated.