MySQL + SQL · Lesson 93
Views in MySQL
What is a View?
A view is a saved query that behaves like a virtual table. It does not store data itself — it shows live data from the underlying tables each time you query it.
Creating a View
CREATE VIEW toppers AS
SELECT name, marks FROM students WHERE marks >= 90;
-- use it like a table
SELECT * FROM toppers;Every time you query "toppers", it runs the saved SELECT on current data.
Why Use Views?
- Hide complex joins behind a simple name.
- Show users only certain columns (security).
- Reuse a common query everywhere.
Removing a View
DROP VIEW toppers;
Summary
- A view is a saved query acting as a virtual table.
- It stores no data; it shows live results from base tables.
- Good for simplifying queries and limiting access.
💻 Live Code Editor
Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.