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 view simplifying a join
Given two tables Employees and Departments, a view is created to show employee names with their department names. What is the output of querying this view?
MySQL
CREATE VIEW EmployeeDept AS SELECT e.name AS employee_name, d.name AS department_name FROM Employees e JOIN Departments d ON e.department_id = d.id; SELECT * FROM EmployeeDept;
Attempts:
2 left
💡 Hint
Think about what columns the view selects and how the join works.
✗ Incorrect
The view selects employee names and their corresponding department names by joining the two tables on department_id. Querying the view returns both columns as shown.
🧠 Conceptual
intermediate1:30remaining
Why use views for complex queries?
Which of the following is the main reason views simplify complex queries?
Attempts:
2 left
💡 Hint
Think about how views help with repeated complex SQL code.
✗ Incorrect
Views act like saved queries. They let you write complex SQL once and then use a simple name to run it again, making queries easier to write and read.
📝 Syntax
advanced2:00remaining
Identify the correct syntax to create a view
Which option correctly creates a view named
TopSellers showing products with sales over 1000?MySQL
CREATE VIEW TopSellers AS SELECT product_name, sales FROM Products WHERE sales > 1000;
Attempts:
2 left
💡 Hint
Remember the correct order of keywords in CREATE VIEW syntax.
✗ Incorrect
Option A uses the correct syntax: CREATE VIEW view_name AS SELECT ... WHERE ...; Option A and C have keyword order errors. Option A misuses HAVING without GROUP BY.
❓ optimization
advanced1:30remaining
How do views help optimize query maintenance?
When a complex query is encapsulated in a view, what is the main optimization benefit for developers?
Attempts:
2 left
💡 Hint
Think about how changing one place affects many queries.
✗ Incorrect
By changing the view's SQL, all queries using that view get updated automatically, reducing repeated edits and errors.
🔧 Debug
expert2:30remaining
Why does this view cause an error?
Given the view creation below, why does it cause an error when executed?
CREATE VIEW RecentOrders AS
SELECT order_id, customer_id, order_date
FROM Orders
WHERE order_date > CURRENT_DATE + 7;
Attempts:
2 left
💡 Hint
Check how date arithmetic is done in SQL.
✗ Incorrect
In MySQL, you cannot add an integer directly to a date using '+'. You must use DATE_ADD or INTERVAL syntax for date arithmetic.