sqlcmd.net validated sql reference
intermediate defining MySQL MariaDB SQL Server PostgreSQL SQLite

Create A Reusable Query With CREATE VIEW

Save a `SELECT` statement as a named view so it can be queried like a table.

Docker-validated Not currently validation-green

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.

Rows loaded before the example query runs.
Setup
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);
Shared across supported engines.
SQL
CREATE VIEW engineering_team AS
SELECT
  id,
  name,
  salary
FROM
  employees
WHERE
  department = 'Engineering';

SELECT
  id,
  name,
  salary
FROM
  engineering_team
ORDER BY
  id;
Returned rows for the shared example.
idnamesalary
1Ada90000
3Carol85000

Output is identical across all engines.

Where this command helps.

  • simplifying a complex query by naming it as a reusable view
  • restricting which columns or rows an application can access

What the command is doing.

A view is a stored query that appears as a virtual table. Querying a view runs the underlying SELECT against the live data — views do not store rows themselves (unless they are materialized views, which is an advanced feature). Views are useful for hiding complexity, enforcing consistent filtering, or restricting which columns an application can access.