Answer the question
In order to leave comments, you need to log in
How to write such sql query?
There is a table of departments ( department ) and a table of employees ( employee ). The unique field in each of them is id.
There is also an employee-department relationship table ( employee_department ) with fields employee_id and department_id .
What will the SQL query look like to get all employees who are not, for example, in a department with ID = 7 ?
Answer the question
In order to leave comments, you need to log in
SELECT * FROM employee WHERE id NOT IN (SELECT employee_id FROM employee_departament WHERE departament_id = 7)
Please clarify - do you have a 1-to-1 comparison?
Then you can probably just
SELECT * FROM employee as e
INNER JOIN employee_department as ed ON e.id = ed.employeeId
WHERE ed.department_id != 7
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question