0
0
MySQLquery~20 mins

Querying from views in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
View Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of querying a simple view
Given a view EmployeeView defined as CREATE VIEW EmployeeView AS SELECT id, name, salary FROM Employees WHERE salary > 50000;, what will be the output of SELECT * FROM EmployeeView WHERE name = 'Alice'; if the Employees table contains:

id | name | salary
1 | Alice | 60000
2 | Bob | 45000
3 | Carol | 70000
ANo rows returned
B2 rows: id=1, name='Alice', salary=60000 and id=3, name='Carol', salary=70000
C3 rows: all employees regardless of salary
D1 row: id=1, name='Alice', salary=60000
Attempts:
2 left
💡 Hint
Remember the view filters employees with salary greater than 50000.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in querying a view
Which of the following queries will cause a syntax error when querying a view named ProductView?
ASELECT * FROM ProductView WHERE price > 100;
BSELECT * ProductView WHERE price > 100;
CSELECT * FROM ProductView GROUP BY category;
DSELECT price, name FROM ProductView;
Attempts:
2 left
💡 Hint
Check the basic SELECT syntax for missing keywords.
optimization
advanced
2:00remaining
Optimizing queries on views with joins
Consider a view OrderSummary defined as:
CREATE VIEW OrderSummary AS SELECT o.id, c.name, o.total FROM Orders o JOIN Customers c ON o.customer_id = c.id;
Which query will be the most efficient to get orders with total > 1000?
ASELECT o.id, c.name, o.total FROM Orders o JOIN Customers c ON o.customer_id = c.id WHERE o.total > 1000;
BSELECT * FROM OrderSummary HAVING total > 1000;
CSELECT * FROM OrderSummary WHERE total > 1000;
DSELECT * FROM OrderSummary WHERE total < 1000;
Attempts:
2 left
💡 Hint
Filtering before joining can improve performance.
🔧 Debug
advanced
2:00remaining
Debugging incorrect results from a view query
A view ActiveUsers is defined as:
CREATE VIEW ActiveUsers AS SELECT id, username FROM Users WHERE status = 'active';
Running SELECT * FROM ActiveUsers WHERE username LIKE '%admin%'; returns no rows, but you know there are active users with 'admin' in their username. What is the most likely cause?
AThe query is case-sensitive and usernames have different case.
BThe Users table has no active users with 'admin' in username.
CThe view definition filters out users with 'admin' in username.
DThe LIKE operator is not supported in views.
Attempts:
2 left
💡 Hint
Consider how string matching works in SQL.
🧠 Conceptual
expert
3:00remaining
Understanding limitations of updatable views
Which of the following statements about updatable views in MySQL is TRUE?
AViews with GROUP BY clauses are always updatable.
BViews that join multiple tables can never be updated directly.
CViews that select from a single table without aggregation can be updatable.
DViews without a primary key cannot be updated.
Attempts:
2 left
💡 Hint
Think about when MySQL allows updates through views.