Answer the question
In order to leave comments, you need to log in
How to get all projects that do not have a connection with a certain user through 2 tables?
2 tables: project, project_user
I want to get all projects that do not have a connection with id 4 for example, even if this project has a connection with another user (that is, it has a connection with id 4 and id 5), I do not want to receive this project at all, despite the 5.
Answer the question
In order to leave comments, you need to log in
i want to get all projects that have no connection with id 4
SELECT p.*
FROM project p
WHERE NOT EXISTS ( SELECT NULL
FROM project_user u
WHERE p.project_id = u.project_id
AND u.user_id = 4 )
... where project.id NOT IN (
select distinct project_id from project_user where user_id=4
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question