Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / May 2005

Tip: Looking for answers? Try searching our database.

UNION in Subquery

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jacob - 18 May 2005 20:34 GMT
Ok, I can do the following

SELECT COUNT(cq.qid)
FROM completed_questions cq

UNION

SELECT cq.qid
FROM completed_questions cq

The problem with this on is taht it will return the count but also the
cq.qids from the other query in the union.

But I can't do the following

SELECT COUNT(cq.cqid)
FROM completed_questions cq
WHERE cq.cqid IN (

SELECT cq.qid
FROM completed_questions cq

UNION

SELECT cq.qid
FROM completed_questions cq)

This query should fix the above problem but it doesn't. Access tells me that
"This operation is not allowed in subqueries."
I could be wrong but by using simple queries like this one, i think i've
come to the conclusion that UNION cannot be used in a subquery when COUNT is
in the main query.  How do i get around this. UNION was the only way i could
combine the two queries into one. Once i've combined those queries, I want to
count the number of cqids that appear. I can use COUNT and a subquery, but i
can't use COUNT and UNION in a subquery. Or maybe I just can't use UNION in a
subquery. Either way, i have this big, complex query that i don't want to
start over on.

Any ideas?
Van T. Dinh - 18 May 2005 23:09 GMT
I can't see the point of using:

....
SELECT cq.qid
FROM completed_questions cq

UNION

SELECT cq.qid
FROM completed_questions cq

Both sides of the Union is exactly the same and since you used UNION and not
UNION ALL, one qid of each pair of qid from the left and right sides of the
Union will be eliminated.  Hence, the above is equivalent to simply:

SELECT cq.qid
FROM completed_questions cq

Describe in words what you try to get, a small sample set of data and the
return of the query required.

Signature

HTH
Van T. Dinh
MVP (Access)

> Ok, I can do the following
>
[quoted text clipped - 35 lines]
>
> Any ideas?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.