I have a table called Employees with a one-to-many relationship to a table called EmpDepts. I have a Departments table containing department records.
EmpDepts contains records of the departments an employee has been assigned to and an employee can be assigned to any number of departments.
So the tables look like this:
Employees:
id last_name
23 Smith
45 Jones
50 Banks
55 Wilson
77 Harris
EmpDepts:
emp_id dept_id
23 63
45 63
Departments
id label
63 Sales
18 Support
23 Accounting
I'm trying to write a query that will show me all employees not assigned to Sales but it only shows me those employees who are in the EmpDepts table and I think that's because of the left join query. How can I write a query that will show Banks, Wilson and Harris as not being assigned to the Sales department? Thanks.
PHP Code:
SELECT E.last_name FROM Employees E LEFT JOIN EmpDepts D ON E.id=D.emp_id WHERE D.dept_id <> 63
__________________
RalphF
Business Text Messaging Services
Please login or register to view this content. Registration is FREE
|