How to create and query Database Views in MySQL?
Encapsulates complex query logic into reusable virtual tables using CREATE VIEW.
-- Create Virtual View for High Earning Employees CREATE VIEW high_earners AS SELECT employee_id, first_name, last_name, salary FROM employees WHERE salary >= 60000; -- Query the View as a normal table SELECT * FROM high_earners; -- Drop View DROP VIEW IF EXISTS high_earners;
Query OK, 0 rows affected (0.01 sec) +-------------+------------+-----------+----------+ | employee_id | first_name | last_name | salary | +-------------+------------+-----------+----------+ | 1 | John | Doe | 60500.00 | | 2 | Alice | Smith | 62000.00 | | 4 | Carol | Williams | 75000.00 | +-------------+------------+-----------+----------+