Example 1
Create a view for the engineering team and query it
The view engineering_team filters out the Finance row and hides the department column. Any query that reads from the view always sees live data — if a new engineer is added to employees, they appear in the view immediately. Use DROP VIEW engineering_team to remove the view.
CREATE TABLE employees (
id INT,
name VARCHAR(50),
department VARCHAR(50),
salary INT
);
INSERT INTO
employees (id, name, department, salary)
VALUES
(1, 'Ada', 'Engineering', 90000),
(2, 'Bob', 'Finance', 70000),
(3, 'Carol', 'Engineering', 85000);CREATE VIEW engineering_team AS
SELECT
id,
name,
salary
FROM
employees
WHERE
department = 'Engineering';
SELECT
id,
name,
salary
FROM
engineering_team
ORDER BY
id;| id | name | salary |
|---|---|---|
| 1 | Ada | 90000 |
| 3 | Carol | 85000 |
Output is identical across all engines.