Mohamed Sharaf

Create a view in MySQL

Save a query under a name and use it like a table.

· 1 min read

From the archive: first published on mohamedsharaf.net in April 2012. Rewritten and checked in 2026; some details may be out of date.

A view is a saved query you can use like a table. Handy when the same filter or join shows up everywhere:

CREATE VIEW active_customers AS
SELECT id, name, email
FROM customers
WHERE status = 'active';

Now SELECT * FROM active_customers works like any table, and the logic lives in one place. To change it later, use CREATE OR REPLACE VIEW.

Views are also a simple access-control tool: give a reporting user permission on the view only, and they never see the columns you left out.

ShareWhatsAppLinkedInXTelegramFacebook