You'd want to select all Employees, and calculate their count of sales for each. Because you'd want all employees in the list, you'd select from the Employees table and either left join to the sales table, or do a subquery to the sales table. Doing this will give you the employees with zero sales in the results as well. In the case of the join, you'd have to group by the employee and count the records in the sales table. For the subquery, there is no group by because your base query will return just 1 row per employee.
select Employees.EmployeeID,
Employees.UserName,
CountOfSales = COUNT(SaleID)
from Employees LEFT JOIN
Sales ON Employees.EmployeeID = Sales.EmployeeID
group by Employees.EmployeeID,
Employees.UserName
/*
EmployeeID UserName CountOfSales
----------- ---------- ------------
2 bill 1
3 larry 0
1 scott 2
Warning: Null value is eliminated by an aggregate or other SET operation.
*/
-- OR --
select E.*,
CountOfSales = (select count(*)
from sales
where EmployeeID = E.EmployeeID)
from Employees E
/*
employeeID username CountOfSales
----------- ---------- ------------
1 scott 2
2 bill 1
3 larry 0
*/
Results from each query are based on the sample data below...
create table Employees (employeeID int , username varchar(10))
create table Sales (saleID int , employeeID int , amount smallmoney)
go
insert Employees values (1, 'steve'), (2, 'bill'), (3, 'larry')
insert Sales values (1, 1, 23), (2,1,33), (3,2,0)
go