There is a users table and a branch_users table

SELECT * FROM `user` INNER JOIN branch_users ON branch_users.user_id = user.id 

I need to select all users from the user table that are not in the branch_users table. That is, if user.id = 1 is in the branch_users table, do not display it, if not, output it.

I can not make a request, there are options?

    1 answer 1

    Something like this

     SELECT * FROM `user` WHERE NOT EXISTS (SELECT * FROM `branch_users` WHERE branch_users.`user_id` = user.`id` ) 

    NOT EXISTS - The operator returns the result: 1 (TRUE) if the result of the subquery does not contain any rows, and 0 (FALSE) if the result of the subquery is non-empty

    • Thanks, somehow I didn’t have to use such an operator, I will know)) - Vlad Shkuta