Link to home
Start Free TrialLog in
Avatar of Sapphireblue
SapphireblueFlag for United States of America

asked on

"Merge" two SQL Server 2000 queries, like Oracle INTERSECT

I have two SQL Server queries I'm manipulating in ColdFusion that I really need to be able to manipulate as one query.

If I were running Oracle, INTERSECT in the query would do what I want in a snap, but no such luck.

Any graceful way to fake an INTERSECT in SQL Server? I expect large datasets, so it would need to be pretty efficient. The two queries are as follows. You can see their results columns are exactly the same.

<cfquery name="GetAllMultipleChoiceResponses" datasource="quiz1">
     SELECT RespondentID, QuestionID, OptionValue AS Response
     FROM MultipleChoiceResponses, Respondents, MultipleChoiceOptions
     WHERE MultipleChoiceResponses.RespondentID = Respondents.ID
     AND MultipleChoiceResponses.OptionID = MultipleChoiceOptions.ID
     AND Respondents.SurveyID = #GetSurveyID#
</cfquery>

<cfquery name="GetAllTextResponses" datasource="quiz1">
     SELECT RespondentID, QuestionID, AnswerText AS Response
     FROM TextResponses, Respondents
     WHERE TextResponses.RespondentID = Respondents.ID
     AND Respondents.SurveyID = #GetSurveyID#
</cfquery>

Bonus points (I can do that, right?) for being able to sort the resulting/combined query by RespondentID ASC, QuestionID ASC!
ASKER CERTIFIED SOLUTION
Avatar of Kevin Hill
Kevin Hill
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sapphireblue

ASKER

Yeah. Someone else pointed out on another section that that's what I wanted, and when he said it, I realized INTERSECT is a whole different thing entirely (gets results that are common to BOTH queries).

So yeah, I'm feeling stupid, but thanks a lot for your help :D
Avatar of Anthony Perkins
Good link Anthony...thanks
Sorry acperkins. I am clearly a dork.