A
A
Artem Prokhorov2021-07-30 14:10:45
SQL
Artem Prokhorov, 2021-07-30 14:10:45

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

2 answer(s)
A
Akina, 2021-07-30
@Akina

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 )

S
Stalker_RED, 2021-07-30
@Stalker_RED

... 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 question

Ask a Question

731 491 924 answers to any question