Re: Graphical Union-Query Builder?



Hi Dave,

If you are limiting the input in each of the sub-queries in your Union
query, then the easier way is to build the Union from the subqueries (which,
if you've followed my earlier advice, will all have the same corresponding
fields), rather than from the subqueries SQL.

So, rather than:
SELECT ...
FROM tblOne
WHERE tblOne.FieldX = ...
UNION ALL
SELECT ...
....

Use the filtered queries as the input to your Union query:
SELECT *
FROM qryFilteredQueryOn TableOne
UNION ALL
SELECT ...

If you want to limit the results from your Union query, then create a new
query based on the union query, and apply the WHERE conditions in that
query.

Again, HTH,

Rob

PS. I noticed your "For Microsoft's Benefit" section. Although this
newsgroup is hosted by MS, they do not (officially) monitor it; and the MVPs
who reply to most questions are not Microsoft employees.

In particular, I think your first comment is far from well-founded.
Building/maintaining an Access application is not something which can be
done by a "functional IT user"; it requires a lot of particular skills and
knowledge. Most "functional IT users" will not know anything about SQL.
And those things, together, are probably why there is no graphical method
for building a Union query: for occasional users (including those who are
reasonably "IT-savvy"), it's beyond their comprehension; for Access
professionals, it's so simple that a graphical interface is not needed.



"David McCulloch" <|@|.|> wrote in message
news:47023dd3$0$24340$4c368faf@xxxxxxxxxxxxxxxxx
Rob,

Thanks for the information. You've saved me a good chunk of time.

I didn't know that fields of subsequent queries in a Union could have
different names. If they happen to have the same names, do I still need
to qualify the field names (t1.field1, t2.field1, etc.) for WHERE and/or
ON conditions?


+ + + + + + + + + + + +
For Microsoft's benefit
+ + + + + + + + + + + +

If Microsoft is listening, please provide a graphical method for building
and maintaining Union queries. Here are a few drawbacks of manually
building Union queries, even from the SQL associated with graphically
constructed Select queries:

1. It requires anyone who builds or maintains an application to know
something about SQL. Often, they will be functional users, not IT
professionals.

2. It requires anyone who maintains an application to know which Select
queries were used to build the Union query. The original programmer might
be able to make it more intuitive with good query naming standards, but
nothing would replace an even moderately designed graphical interface that
would display the Union's individual query names.

3. It requires much more maintenance time -- and time is money -- than if
Microsoft provided this relatively simply graphical interface for building
and maintaining Union queries (sorry for the venting!).

Dave


"Rob Parker" <NOSPAMrobpparker@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:ujXld9JBIHA.4568@xxxxxxxxxxxxxxxxxxxxxxx
Hi David,

Microsoft (ie. Access) doesn't have one, and I'm not aware of any third
party ones.

That said, creating a Union query isn't that difficult. Simply build
each part as a separate query, ensuring that they all have the same
number of fields (they don't have to have the same names - the Union
query will use the fields names from the first sub-query), in the same
order. You can insert null or constant fields in any of the individual
select queries if necessary to get the correct number of fields, in the
correct order. Then open each one in SQL view, and cut/paste into the
SQL view of your new Union query, replacing the closing semicolon of each
one with "UNION " (or "UNION ALL " if you don't want to exclude duplicate
records). It's pretty quick in practice.

HTH,

Rob

"David McCulloch" <|@|.|> wrote in message
news:4701aad1$0$20566$4c368faf@xxxxxxxxxxxxxxxxx
I have two moderately complex queries (each one has at least 7-tables and
several more joins) that must be combined via a Union query. The results
will be used in subsequent queries. Writing and maintaining SQL for this
Union query is a last resort. How can I keep my application as intuitive
and as low-maintenance as possible?

1. Does Microsoft or anyone else have a graphical user interface for
building Union queries yet?

2. Does any tool exist that could read user-specified Select queries in
Access and create the corresponding Union query? I've been considering
writing such a tool out of necessity.

Dave







.



Relevant Pages

  • Re: Please help me evolve this concept
    ... complex SQL SELECT statements including UNION, OUTER JOINS, GROUP BY, ... It sure will save you a lot of time and coding if all you need is to query ... I could modify this in code and qActorSelect stays 'dynamically ... creating a union query based on qActorSelect as opposed to ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Combining records from two queries
    ... combining UNION and SELECT queries to best effect. ... Using my query names, can you say exactly what my SQL should be ... > my Union Queries short and simple and do the rest of the work elsewhere. ... >>> Subject and Professional Mentors that are allocated to placements. ...
    (microsoft.public.access.queries)
  • Re: Question about Queries with Subqueries
    ... performance reasons to use UNION ALL instead of UNION. ... i have a query i am working on that draws data from 3 different data ... i have a question about queries like this. ... to try "flattening" my queries by using subqueries. ...
    (microsoft.public.access.queries)
  • RE: adding 2 fields including null entries
    ... First I'll go through the method that will not use the crosstabs. ... we'll define the select query for the PSS Names: ... Note that you could paste the sql from either of the queries above in the ... Next, we want to combine these results, so we use a union statement. ...
    (microsoft.public.access.queries)
  • RE: number of columns doesnt match bug in Access
    ... The naming of the fields using reserved words could be an source of problems ... Also you use as an alias in the SQL. ... as they must in a Union Join. ... I have a union query which regularily generates the "number of columns ...
    (microsoft.public.access.queries)