MySQL Multiple "AND" Query
Posted
by
Mark J
on Stack Overflow
See other posts from Stack Overflow
or by Mark J
Published on 2012-09-08T03:25:27Z
Indexed on
2012/09/08
3:38 UTC
Read the original article
Hit count: 127
I have a table with 2 columns (see below). A member can have multiple responses to a question
RESPONSES
---------
member_id INT
response_id INT
SAMPLE DATA
member_id -- response_id
1 -- 3
1 -- 5
2 -- 1
2 -- 5
2 -- 9
3 -- 1
3 -- 5
3 -- 6
What I need to do is query the table for member that meet ALL response criteria. For example I need to select all members that have a response_id of 1 AND 5. I am using the following query:
SELECT DISTINCT member_id FROM responses WHERE response_id = 1 AND response_id = 5.
I would expect to get back member_id's 2,3. However I am getting nothing returned. I used EXPLAIN and it shows there is an error in my where query. What am I doing wrong?
Also, is there a function similar to IN where all the criteria must be met in order to return true?
Thanks for your help.
© Stack Overflow or respective owner