Query problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

With the following table structure:

RuleID
QuestionID
Response

There are a fixed number of questions (currently 10) which apply to each rule.

For each Question where all of the Responses are the same across all Rules,
I need to list the rules.
I'd like the output to be a table with 2 columns: Question and Rule

Can anyone think of an efficient way to do it?

-David
 
I'm assuming this means that one rule can be used for multiple questions,
and that your data looks like this:

QID, RID, Response
1, 1, Truck
1, 2, Boat
2, 1, Truck
2, 2, RV
3, 1, Truck
3, 2, Motorcycle

Then I would Group By RID & Response to find those with a Count(QID) equal
to the total count of questions. From there, you would use all that info to
query for the QID & RID that make the cut.

I'd do it in about 3 queries or so..
 
Untested idea

SELECT QuestionID, RuleID
FROM TheTable
WHERE QuestionID In (
SELECT QuestionID
FROM TheTable
GROUP BY QuestionID, Response
HAVING Count(Response) = 10)
 
Back
Top