I have this table in MySQL
database :
table1
User_id type
2 1
1 2
2 3
I want to get the users_id of users with type 2 or 3 only when their user_id value is different from the user_id with the type=1.
hope you got the idea and you can help me I didn't know what to use to solve his.
CodePudding user response:
I want to get the users_id of users with type 2 or 3 only when their user_id value is different from the user_id with the type=1.
It can be written pretty much the same in SQL
SELECT *
FROM users
WHERE type IN (2,3) and user_id NOT IN (SELECT user_id FROM users WHERE type = 1)
CodePudding user response:
SELECT
user_id,
type,
FROM
yourTable
WHERE type IN (2,3)
AND user_id NOT IN (
SELECT
user_id
FROM yourTable
WHERE type = 1)