I have a query that I need help on. The cc_division table is a lookup. In my results I want to display all divisions regardless of the results. The statement works fine except I am limiting my results in the where clause. Can anyone tell me how I could do the exact thing below so that I can return all of the items in my lookup?
Thanks
Here is my SQL statement:
SELECT DISTINCT dbo.cc_division.division, dbo.cc_division.division_id, COUNT(dbo.cc_employee.employee_key) AS total
FROM dbo.cc_employee RIGHT OUTER JOIN
dbo.cc_division ON dbo.cc_employee.division_id = dbo.cc_division.division_id
WHERE (dbo.cc_employee.employee_key NOT IN
(SELECT employee_key
FROM cc_card
WHERE active = 1))
GROUP BY dbo.cc_division.division, dbo.cc_division.division_id
One way to do it would be like this:
SELECT DISTINCT dbo.cc_division.division, dbo.cc_division.division_id, COUNT(cc_employee.employee_key) AS total
FROM (SELECT *FROM dbo.cc_employee WHERE dbo.cc_employee.employee_key NOT IN
(SELECT employee_key
FROM cc_card
WHERE active = 1)) AS cc_employee RIGHTOUTER JOIN
dbo.cc_division ON cc_employee.division_id =dbo.cc_division.division_id
GROUP BY dbo.cc_division.division, dbo.cc_division.division_id
I haven't tested it so there might be syntax errors.
|||perfect thank you
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment