Introduction
Views let you save a query as a virtual table. Querying from views helps you reuse complex queries easily without rewriting them.
Views let you save a query as a virtual table. Querying from views helps you reuse complex queries easily without rewriting them.
SELECT column1, column2 FROM view_name WHERE condition;
employee_view.SELECT * FROM employee_view;
SELECT name, salary FROM employee_view WHERE salary > 50000;
SELECT department, COUNT(*) FROM employee_view GROUP BY department;
This creates a view called employee_view that selects some columns from the employees table. Then it queries the view to find employees with salary over 60,000.
CREATE VIEW employee_view AS SELECT id, name, department, salary FROM employees; SELECT name, salary FROM employee_view WHERE salary > 60000;
Views do not store data themselves; they run the saved query each time you use them.
Updating data through views is possible only if the view is simple and meets certain rules.
Views let you save and reuse queries as virtual tables.
You query views just like normal tables.
Views help simplify complex queries and improve security.
employee_view?sales_view defined as SELECT product_id, SUM(quantity) AS total_qty FROM sales GROUP BY product_id, what will the query SELECT * FROM sales_view WHERE total_qty > 100; return?customer_view defined as SELECT id, name, email FROM customers; but running SELECT phone FROM customer_view; gives an error. What is the problem?active_users_view that shows only users with status = 'active' from the users table. Which query correctly creates this view?Pass the test and this pattern moves unknown