?
Solved

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

Posted on 2005-03-02
5
Medium Priority
?
909 Views
Last Modified: 2007-11-27
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!
0
Comment
Question by:Sapphireblue
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 21

Accepted Solution

by:
Kevin3NF earned 2000 total points
ID: 13443682
Don't know Oracle, but it looks like you are asking for UNION  (or UNION ALL)

Select A,B From table1

Union

Select A,B From table 2

Order bY (your fields here)

Am I understanding the question?
0
 
LVL 1

Author Comment

by:Sapphireblue
ID: 13443753
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
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13443761
0
 
LVL 21

Expert Comment

by:Kevin3NF
ID: 13443842
Good link Anthony...thanks
0
 
LVL 1

Author Comment

by:Sapphireblue
ID: 13443912
Sorry acperkins. I am clearly a dork.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question