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 the table Employees with columns
What will be the output of
id, name, and salary, and the view 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 Employees table contains:id | name | salary 1 | Alice | 60000 2 | Bob | 45000 3 | Charlie | 70000
SQL
CREATE VIEW HighEarners AS SELECT name, salary FROM Employees WHERE salary > 50000;
Attempts:
2 left
💡 Hint
The view filters employees with salary greater than 50000 and only selects name and salary columns.
✗ Incorrect
The view HighEarners selects only the name and salary columns from Employees where salary is greater than 50000. Bob is excluded because his salary is 45000.
🧠 Conceptual
intermediate1:30remaining
Understanding view updates
Which of the following statements about SQL views is TRUE?
Attempts:
2 left
💡 Hint
Think about whether views hold data or just a query definition.
✗ Incorrect
Views are saved queries that do not store data themselves. When you query a view, it runs the underlying query on the base tables and shows current data.
📝 Syntax
advanced2:00remaining
Identify the syntax error in view creation
Which option contains a syntax error when creating a view that lists product names and their categories from tables
Products and Categories?SQL
Tables: Products(product_id, product_name, category_id) Categories(category_id, category_name)
Attempts:
2 left
💡 Hint
Check the syntax for the CREATE VIEW statement carefully.
✗ Incorrect
Option A is missing the keyword 'AS' after the view name, which is required in standard SQL syntax for creating views.
❓ optimization
advanced2:30remaining
Performance impact of views
Consider a view defined as:
If the Sales table has millions of rows, which approach is generally better for performance when querying large sales data?
CREATE VIEW LargeSales AS SELECT * FROM Sales WHERE amount > 10000;
If the Sales table has millions of rows, which approach is generally better for performance when querying large sales data?
Attempts:
2 left
💡 Hint
Think about how data storage and indexing affect query speed.
✗ Incorrect
Materialized views store the query result physically and can be indexed, improving performance for large datasets compared to querying a standard view which runs the query each time.
🔧 Debug
expert3:00remaining
Diagnose the error when querying a view
A view is created as:
When running
CREATE VIEW ActiveUsers AS SELECT id, name FROM Users WHERE status = 'active';
When running
SELECT * FROM ActiveUsers;, the error ERROR: relation "activeusers" does not exist appears. What is the most likely cause?Attempts:
2 left
💡 Hint
Consider how database schemas and search paths affect object visibility.
✗ Incorrect
The error indicates the view does not exist in the current search path. It is likely created in another schema or database, so the query cannot find it without schema qualification.