Skip to main content

How do you create a view?

A view is created with the CREATE VIEW command.

The syntax is simple:

sql
CREATE VIEW view_name AS SELECT columns FROM table_name WHERE condition;

Example

sql
CREATE VIEW active_users AS SELECT id, name, email FROM users WHERE is_active = 1;

Now you can query it like a regular table:

sql
SELECT * FROM active_users;

To update a view's logic, use:

sql
CREATE OR REPLACE VIEW active_users AS SELECT id, name FROM users WHERE last_login > '2025-01-01';

This creates or replaces the view without dropping the old one first.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.