Introduction
Views let you save a query as a virtual table. This makes it easier to reuse complex queries 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';
CREATE TABLE employees ( id INT PRIMARY KEY, name VARCHAR(50), department VARCHAR(50), salary INT ); INSERT INTO employees VALUES (1, 'Alice', 'Sales', 50000), (2, 'Bob', 'HR', 45000), (3, 'Charlie', 'Sales', 55000), (4, 'Diana', 'IT', 60000); CREATE VIEW sales_team AS SELECT id, name, salary FROM employees WHERE department = 'Sales'; SELECT * FROM sales_team;
employee_view showing id and name from employees table?products with columns id, name, and price, what will be the output of SELECT * FROM cheap_products; if cheap_products is created as CREATE VIEW cheap_products AS SELECT id, name FROM products WHERE price < 50;?CREATE VIEW sales_view AS SELECT order_id, total FROM orders WHERE;active_customers that shows customer id, name, and their total orders from customers and orders tables. Which query correctly creates this view?Pass the test and this pattern moves unknown