A view in MySQL is a virtual table defined by a SELECT query. It behaves like a table (rows & columns) but does not store data itself — it shows the result set produced by its underlying query whenever accessed.
-- CREATE VIEW syntax: define a virtual table from a SELECT
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
-- Create a view showing employees aged 18 or older
CREATE VIEW EmployeeView AS
SELECT Name, Age, Salary
FROM Employees
WHERE Age >= 18;
-- Query the view just like a table to retrieve its rows
SELECT * FROM EmployeeView;
-- Combine employees with their department names
CREATE VIEW EmpDept AS
SELECT e.Id, e.Name, d.DepartmentName, e.Salary
FROM Employees e
JOIN Departments d ON e.DepartmentId = d.Id;
When you run SELECT * FROM EmployeeView; MySQL executes the view's SELECT and returns the resulting rows. The view acts as a read-only lens over your underlying tables (unless it's an updatable view).
Employees and Departments showing employee name and department.Name and DepartmentName for regular users.