Reputation: 9703
I am trying to select multiple rows based on 3 columns matching particular criteria. For a single search I do the following:
SELECT user_id
FROM users_to_users
WHERE user_id = '1' AND contact_user_id = '9' AND contact_blocked = 1
I would like to submit a set of values to return multiple rows.
so my values would be as such:
('1', '9', 1), ('2, '9', 1),('3', '9', 1) etc...
And return user_id's for the rows which match. In essence I'm trying to see which users have blocked user '9' so that I could then add only the users that are not blocked to the next statement.
Being very unfamiliar with SQL what I thought might work was the following:
SELECT user_id
FROM users_to_users
WHERE (user_id, contact_user_id, contact_blocked) VALUES (...)
But unable to do that. Is there any way to select multiple rows based on matching conditions for multiple columns?
Upvotes: 3
Views: 70
Reputation: 1269463
Are you trying to use tuples with in
? If so, this works:
SELECT user_id
FROM users_to_users
WHERE (user_id, contact_user_id, contact_blocked) in ( (1, 9, 1), (2, 9, 1), (3, 9, 1) )
There may be other ways, however, to accomplish your ultimate goal.
Upvotes: 3