Reputation: 35
I have a table of answers with column fields like:
questionID,answer,email
row1: questionID = 'q1', answer = 'Male', email = '[email protected]'
row2: questionID = 'q2', answer = 'Human',email = '[email protected]'
I want to have a select statement like this:
SELECT email
FROM answers
WHERE (questionID='q1' AND answer='Male')
AND (questionID='q2' AND answer='Human')
So in other words, I want to the email of all of the people that are male, and human. The thing is each 'answer' is a new row so this query does not work. Is there a way to do this easily? Thanks!
Upvotes: 2
Views: 98
Reputation: 204746
SELECT email FROM answers
WHERE answer='Male' OR answer='Human'
group by email
having count(distinct answer) = 2
Upvotes: 4