Re: Multi-Level GROUP By Clause is not allowed in subquery



Glad to hear that you got it working.

It should work with UNION, but UNION eliminates duplicate
records (same as DISTINCT), which is a (big) waste of time.
If you want any duplicate records, then UNION would just be
wrong. If you did not want duplicates, your original
query's DISTINCT predicate would have already taken care of
it. If there can not be any duplicates in your original
query, then UNION just wastes a lot of time looking for
nonexistant duplicates.

Note that the WHERE clause in the silly Select query should
be more than a simple WHERE False. You should choose a
small table that has a primary key and compare that to an
impossible value (e.g. WHERE Key = 0). The point is to
allow the query engine to use the index to eliminate all the
records instead of retrieving all the records just to
evaluate False on every record.
--
Marsh
MVP [MS Access]


Souris wrote:
Thanks millions for the information,

Do you mean that I change select query to union query and at the end to
union all?

Does it work using union or must union all?


"Marshall Barton" wrote:

Souris wrote:

I use a query which includes subquery to generate my report, because they are
not in the same table.

I got "Multi-Level GROUP By Clause is not allowed in subquery" message when
I run the report.

MS Access lets me create the report using the query.

The query works fine when I run it.

Does MS Access report support subquery?
If not, any work around?


The problem with a subquery in a report's record source
happens when the report uses an aggregate function (Count,
Sum, etc) or has groups (via Sorting and Grouping). In this
case, the internally generated query that the report
actually uses adds additional GROUP BY clauses that breaks
in the presence of some(?) subqueries.

The standard workaround is to use a domain aggregate
function (DLookup, DCount, DSum, etc) instead of a subquery.

If that's not feasible, then the only other workaround I
know of is kind of ridiculous, but it has always worked for
me. Add this kind of glop to the end of your query:

UNION ALL
SELECT Null, Null, Null, Null, ...
FROM [a small table]
WHERE (some condition that is always false)
.



Relevant Pages

  • RE: union query for report
    ... I have a report with 14 subreports. ... but the enter parameter value for A1aC display 12 times. ... The other 6 are based on 6 union ... I wondered if the problem would be using the query, qYr2ReviewSample, in the ...
    (microsoft.public.access.reports)
  • Re: Sum of numbers
    ... Administrator to come in to insure we have this critical report by April. ... You say the union query 'only shows fields from the first table'. ... Do you mean that you want a multicolumn report with all customers' names ...
    (microsoft.public.access.reports)
  • Re: Establishing Precedence In ORDERBY Condition Causing Problems.
    ... in the query, prefix all your columns with aliases (or the table ... in the query where you use the CTE: ... of the procedure to avoid duplicates it seems to have thrown off the ...
    (comp.databases.ms-sqlserver)
  • Re: SQL Select Query Help
    ... I should be approaching this as a union and not trying to ... If I type all the rows (pay or deduction) ... > in the case of your report, there IS no logical relationship - so I had to ... > query in chronological order. ...
    (microsoft.public.sqlserver.programming)
  • Re: This Month vs Last Month
    ... UNION ALL ... Then create a crosstab query based on the union query with (should be ... Heading, Area as another Row Heading, "Mth" & MthNum as the Column Heading, ... The report is currently being pulled for the ...
    (microsoft.public.access.reports)