SQL Views Complex views

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

A view can be a really complex query(aggregations, joins, subqueries, etc). Just be sure you add column names for everything you select:

Create VIEW dept_income AS
SELECT d.Name as DepartmentName, sum(e.salary) as TotalSalary
FROM Employees e
JOIN Departments d on e.DepartmentId = d.id
GROUP BY d.Name;

Now you can select from it as from any table:

SELECT * 
FROM dept_income;
DepartmentNameTotalSalary
HR1900
Sales600


Got any SQL Question?