Connecting Tech Pros Worldwide Forums | Help | Site Map

SubQuery problem

Kaur
Guest
 
Posts: n/a
#1: Sep 7 '06
Hi,

I am having problem getting desired results from the second part of the
query with a subquery. My query looks like this.
SELECT tblSurveyResponse.SurveyID, tblSurveyResponse.SurveyEditionID,
tblSurveyResponse.QuestionID
FROM LkupQuestions INNER JOIN tblSurveyResponse ON
LkupQuestions.QuestionID = tblSurveyResponse.QuestionID
GROUP BY tblSurveyResponse.SurveyID, tblSurveyResponse.SurveyEditionID,
tblSurveyResponse.QuestionID
HAVING (((tblSurveyResponse.SurveyID) In (Select S.SurveyID from
tblSurvey S inner join tblSurveyEditions SE on S.SurveyID =
se.SurveyID group by S.SurveyID having Count(*) 1 )));
This part works fine. This gives me a result set that looks like this.
Survey SurveyEdition Question SurveyResponse
1 1 1 1
1 2 1 2
2 1 1 7
2 2 2 3
Quote:
>From this result set I want to pick up the questions that exits in more
than one survey edition for a given survey. In this case it would Be
Question 1 and Survey 1 since Question 1 exists in both the editions of
Survey 1.
I donot seem to create a query that will retrieve this result set.

Any help would be appreciated.


jrchase@prodigy.net
Guest
 
Posts: n/a
#2: Sep 7 '06

re: SubQuery problem


Kaur,

Try a Group by query on your last query results, where you will set
Survey, Survey Edition and Question to "Group By". Then add one of
those fields again and set it to "Count". Filter the field set to
Count to >1 and you should have the results you want.

Regards,
Jerry Chase

Kaur
Guest
 
Posts: n/a
#3: Sep 8 '06

re: SubQuery problem



jrchase@prodigy.net wrote:
Quote:
Kaur,
>
Try a Group by query on your last query results, where you will set
Survey, Survey Edition and Question to "Group By". Then add one of
those fields again and set it to "Count". Filter the field set to
Count to >1 and you should have the results you want.
>
Regards,
Jerry Chase
Thanks Jerry, that worked. I was trying to do all of it in one query
with subqueries. I guess I have to create two queries in order to
achieve above results.

Kaur

Closed Thread