0
0
SQLquery~20 mins

Querying through views in SQL - 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 table Employees with columns id, name, and department, and a view View_DeptSales defined as SELECT id, name FROM Employees WHERE department = 'Sales', what is the output of SELECT * FROM View_DeptSales ORDER BY id; if the Employees table contains:

id | name | department
1 | Alice | Sales
2 | Bob | HR
3 | Carol | Sales
SQL
CREATE VIEW View_DeptSales AS SELECT id, name FROM Employees WHERE department = 'Sales';

SELECT * FROM View_DeptSales ORDER BY id;
A
1 | Alice
2 | Bob
B
2 | Bob
3 | Carol
C
1 | Alice
3 | Carol
D
1 | Alice
2 | Bob
3 | Carol
Attempts:
2 left
💡 Hint
Remember the view filters only employees in the Sales department.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in view creation
Which option contains a syntax error when creating a view that selects name and salary from Employees where salary is above 50000?
ACREATE VIEW HighEarners AS SELECT name, salary FROM Employees WHERE salary > 50000;
BCREATE VIEW HighEarners AS SELECT name, salary FROM Employees WHERE salary > 50000 ORDER BY salary;
CCREATE VIEW HighEarners AS SELECT name, salary FROM Employees WHERE salary > 50000
DCREATE VIEW HighEarners AS SELECT name salary FROM Employees WHERE salary > 50000;
Attempts:
2 left
💡 Hint
Check the SELECT clause for missing commas.
optimization
advanced
2:00remaining
Optimizing queries using indexed views
You have a large Sales table with millions of rows. You create a view View_TotalSales that sums sales by region. Which option best improves query performance when selecting total sales per region?
ACreate an indexed view (materialized view) with SUM aggregation on region and query it.
BCreate a regular view with SUM aggregation and query it directly.
CCreate a view without aggregation and perform SUM in each query.
DAvoid views and always query the base table with SUM aggregation.
Attempts:
2 left
💡 Hint
Think about pre-computing aggregates for faster queries.
🔧 Debug
advanced
2:00remaining
Debugging unexpected results from a view
A view View_ActiveUsers is defined as SELECT id, name FROM Users WHERE active = TRUE. However, querying SELECT * FROM View_ActiveUsers; returns no rows, even though the Users table has active users. Which option explains the most likely cause?
AThe <code>active</code> column is stored as '1' and '0' strings, not boolean TRUE/FALSE.
BThe view definition is missing a semicolon at the end.
CThe <code>Users</code> table is empty.
DThe query on the view is missing a WHERE clause.
Attempts:
2 left
💡 Hint
Check data types and values in the active column.
🧠 Conceptual
expert
2:00remaining
Understanding view update limitations
Which of the following statements about updating data through views is correct?
AAll views can be updated directly regardless of complexity.
BViews that include joins or aggregations generally cannot be updated directly.
CViews created with SELECT * are never updatable.
DViews with WHERE clauses are never updatable.
Attempts:
2 left
💡 Hint
Think about what makes a view updatable or not.