Challenge - 5 Problems
View Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of a simple view query
Given a table Employees with columns
id, name, and salary, and a view HighEarners defined as CREATE VIEW HighEarners AS SELECT name, salary FROM Employees WHERE salary > 50000;, what will be the output of SELECT * FROM HighEarners; if the table contains:id | name | salary
1 | Alice | 60000
2 | Bob | 45000
3 | Carol | 70000MySQL
CREATE VIEW HighEarners AS SELECT name, salary FROM Employees WHERE salary > 50000; SELECT * FROM HighEarners;
Attempts:
2 left
💡 Hint
The view filters employees with salary greater than 50000 and selects only name and salary columns.
✗ Incorrect
The view selects only employees with salary > 50000 and only the name and salary columns. Bob is excluded because his salary is 45000.
🧠 Conceptual
intermediate2:00remaining
Understanding view update restrictions
Which of the following statements about updating data through a MySQL view is correct?
Attempts:
2 left
💡 Hint
Think about what happens when a view groups or summarizes data.
✗ Incorrect
Views with GROUP BY or aggregates summarize data, so updating them is not allowed because it is unclear how to apply changes to the underlying tables.
📝 Syntax
advanced2:00remaining
Identify the correct syntax to create a view
Which option correctly creates a view named
TopProducts that shows product_name and price from the Products table where price is greater than 100?Attempts:
2 left
💡 Hint
Remember the order: CREATE VIEW view_name AS SELECT ...
✗ Incorrect
The correct syntax is CREATE VIEW view_name AS SELECT ... The other options have incorrect keyword order or missing AS.
❓ optimization
advanced2:00remaining
Improving performance of a view with joins
You have a view
OrderDetailsView that joins Orders and Customers tables. The view is slow when queried. Which approach will most likely improve query performance?Attempts:
2 left
💡 Hint
Indexes help speed up joins by quickly locating matching rows.
✗ Incorrect
Adding indexes on join columns helps the database find matching rows faster, improving performance.
🔧 Debug
expert2:00remaining
Diagnosing error when creating a view
You run this statement:
But MySQL returns an error: "ERROR 1349 (HY000): View's SELECT contains a subquery in the FROM clause". What is the most likely cause?
CREATE VIEW RecentSales AS SELECT sale_id, sale_date FROM (SELECT * FROM Sales) AS tmp WHERE sale_date > NOW() - INTERVAL 30 DAY;But MySQL returns an error: "ERROR 1349 (HY000): View's SELECT contains a subquery in the FROM clause". What is the most likely cause?
Attempts:
2 left
💡 Hint
Check if the SELECT statement has any subqueries inside FROM.
✗ Incorrect
MySQL does not allow views to contain subqueries in the FROM clause. The error indicates such a subquery exists.