By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,568 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,568 IT Pros & Developers. It's quick & easy.

AND query in survey table

P: n/a
Hi!

I have the following table:

id, questions, answers
1,q1,1
2,q1,5
1,q3,2
3,q1,3
4,q1,5
1,q2,2
2,q3,1
2,q2,1
etc

If I need to count together all the possible answers to q1 OR q2 then
I use the following query:

SELECT answers, count(answers) FROM table WHERE questions = q1 OR
questions = q2 GROUP BY answers;

But how the query looks like if I want to count all the possible
answers ONLY in those cases where answers to q1 AND q2 are the same?

Please advice.
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Do you mean

SELECT table.answers, Count(table.answers) AS CountOfAnswers
FROM table INNER JOIN table AS table_1 ON table.answers = table_1.answers
GROUP BY table.queestions, table_1.questions, table.answers
HAVING (((table.questions)="q1") AND ((table_1.questions)="q2"));

?
Bas Hartkamp

"Abhi" <go****@megadelfi.com> wrote in message
news:1d**************************@posting.google.c om...
Hi!

I have the following table:

id, questions, answers
1,q1,1
2,q1,5
1,q3,2
3,q1,3
4,q1,5
1,q2,2
2,q3,1
2,q2,1
etc

If I need to count together all the possible answers to q1 OR q2 then
I use the following query:

SELECT answers, count(answers) FROM table WHERE questions = q1 OR
questions = q2 GROUP BY answers;

But how the query looks like if I want to count all the possible
answers ONLY in those cases where answers to q1 AND q2 are the same?

Please advice.

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.