I have three tables in a survey system (that I didn't design)

surveys (the instance of a user taking a survey) with survey_id and show_id 
(each survey is in response to a particular show) 

responses (possible responses to questions) with response_id

response_map ( survey_id, response_id ) representing a user's answer to a 
survey.

I'm trying to determine how many surveys per show responded with response_id 
30 and response_id 28

I think I need a union here, but am not sure.

So far, I THINK I can figure out how many surveys per show responded with just 
response 30 as follows:

SELECT COUNT(m.survey_id) cnt, s.show_id FROM surveys s, response_map m WHERE 
m.response_id = 30 AND m.survey_id = s.survey_id GROUP BY s.show_id


Am I right in assuming that the following would give me the count of surveys 
per show that had both response 30 and 28 with the following?

SELECT COUNT(m.survey_id) cnt, s.show_id FROM surveys s, response_map m WHERE 
m.response_id = 30 AND m.survey_id = s.survey_id GROUP BY s.show_id UNION 
SELECT COUNT(m.survey_id) cnt, s.show_id FROM surveys s, response_map m WHERE 
m.response_id = 28 AND m.survey_id = s.survey_id GROUP BY s.show_id;    


Thanks in advance for any help

kabel

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to