I try to combine two select query, but I get Error
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists
First select query:
SELECT
dbo.Employees.Name,
dbo.Employees.Salary
FROM
dbo.Employees
Second select query:
SELECT
dbo.Employees.Name AS Employee,
dbo.Employees.Salary AS Salary,
dbo.Salary.Bonus AS Bonus,
dbo.Employees.Salary + dbo.Salary.Bonus AS BonusSalary
FROM
dbo.Employees
INNER JOIN
dbo.Salary ON dbo.Employees.Id = dbo.Salary.Employee
WHERE
dbo.Salary.Year = 2023
AND dbo.Salary.Month = 5
The problem is that I need to combine these two queries. If there are not enough employees in the second query, I need to display them anyway.
I need to display absolutely all employees, regardless of the date
I tried to use UNION and EXCEPT But I get above error
2条答案
按热度按时间e0bqpujr1#
But, as you don't actually use the
Months
table, it can be simplified to...3htmauhk2#
I realized that you want the whole employee to calculate her salary if it is in the salary table
dbfiddle