Introduction
A view lets you save a query as a virtual table. It helps you reuse complex queries easily without rewriting them.
Jump into concepts and practice - no test required
A view lets you save a query as a virtual table. It helps you reuse complex queries easily without rewriting them.
CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition;
CREATE VIEW active_customers AS SELECT id, name, email FROM customers WHERE status = 'active';
CREATE VIEW product_prices AS SELECT product_id, price FROM products;
CREATE VIEW recent_orders AS SELECT order_id, customer_id, order_date FROM orders WHERE order_date > '2024-01-01';
This creates a view named high_salary_employees that shows employees earning more than 70000. Then it selects all rows from this view.
CREATE VIEW high_salary_employees AS SELECT employee_id, name, salary FROM employees WHERE salary > 70000; SELECT * FROM high_salary_employees;
Views do not store data themselves; they run the saved query each time you use them.
You can update data through views only if they meet certain rules (like no joins or aggregates).
Dropping a view does not affect the original tables.
CREATE VIEW saves a SELECT query as a virtual table.
Views simplify complex queries and improve data access control.
You use views by selecting from them like regular tables.
CREATE VIEW statement in SQL?EmployeeView that selects all columns from the Employees table?CREATE VIEW ActiveUsers AS SELECT id, name FROM Users WHERE active = 1;SELECT * FROM ActiveUsers; return?CREATE VIEW SalesView SELECT * FROM Sales;TopProducts that shows product names and total sales only for products with sales over 1000. Which SQL statement correctly creates this view?