-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy path18.views
More file actions
36 lines (27 loc) · 1.37 KB
/
Copy path18.views
File metadata and controls
36 lines (27 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
My complete SQL Masterclass Notes in Tanglish is now live! Covers 30+ topics with syntax, examples, and step-by-step explanations.
Perfect for both beginners and professionals to master SQL easily. Check it out here 👉 https://topmate.io/dataengineering/1697791
====================================================================================
A view in SQL is essentially a virtual table that is defined by a SQL query. Unlike a regular table, a view does not store data physically.
Instead, it dynamically retrieves data from one or more underlying tables (or even other views) whenever you query it.
-- Create the Employees table
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Salary DECIMAL(10,2),
Department VARCHAR(50)
);
-- Insert sample data into the Employees table
INSERT INTO Employees (EmployeeID, FirstName, LastName, Salary, Department)
VALUES
(1, 'Alice', 'Johnson', 55000.00, 'Sales'),
(2, 'Bob', 'Smith', 60000.00, 'IT'),
(3, 'Carol', 'Davis', 52000.00, 'Sales'),
(4, 'Dave', 'Wilson', 58000.00, 'HR');
-- Create a view that shows only employees in the Sales department
CREATE VIEW SalesEmployees AS
SELECT EmployeeID, FirstName, LastName, Salary
FROM Employees
WHERE Department = 'Sales';
-- Now, you can query the view like a table:
SELECT * FROM SalesEmployees;