Re: Union sort
- From: "David F Cox" <nospam@xxxxxxxxxx>
- Date: Fri, 20 Oct 2006 22:45:35 +0100
You can treat the UNION query as though it were a table, and SELECT and
ORDER BY
You will have a bit of work with field names, alas.
FWIW this worked:
SELECT pets AS [pets_], name1 as [name1_]
FROM
(SELECT Pets, name1 FROM Table1)
UNION
(SELECT location AS Pets, Name1 FROM Table1)
ORDER BY [Pets_];
"rachael" <rachael@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:802D44DA-600E-4E63-B9A3-774CECE9AFA7@xxxxxxxxxxxxxxxx
I have a union query that is combining the results of several other
queries.
I have a specific sort order that I need to maintain - this sort order is
built into the individual queries, but not the union query that joins them
together. The problem is there is no easy way to use ORDER BY on the union
results to get the order I need. What I need at the end is an order like:
Organization A - [blank field] - [blank field] - Geography A
Organization A - [blank field] - [blank field] - Geography B
Organization A - [blank field] - [blank field] - Geography C
--------------------------------------------------------------------- [end
of 1st query]
Organization O - [blank field] - [blank field] - [blank field]
Organization O - [SubOrg A] - [blank field] - [blank field]
Organization O - [SubOrg A] - [Group A] - [blank field]
Organization O - [SubOrg A] - [Group B] - [blank field]
Organization O - [SubOrg A] - [Group C] - [blank field]
Organization O - [SubOrg B] - [blank field] - [blank field]
Organization O - [SubOrg C] - [blank field] - [blank field]
--------------------------------------------------------------------- [end
of 2nd query]
Organization M - [blank field] - [blank field] - [blank field]
Organization M - [SubOrg A] - [blank field] - [blank field]
Organization M - [SubOrg B] - [blank field] - [blank field]
Organization M - [SubOrg C] - [blank field] - [blank field]
--------------------------------------------------------------------- [end
of 3rd query]
Organization C - [blank field] - [blank field] - [blank field]
Organization D - [blank field] - [blank field] - [blank field]
Organization E - [blank field] - [blank field] - [blank field]
--------------------------------------------------------------------- [end
of 4th query]
etc...
I can't really create a static table (or don't know how) that lists the
proper sort order for these results, which I could then link to the union
results to sort after the fact. The organizations, etc. in this data will
change over time and it would be difficult to maintain a static table. Any
advice?
Thanks
rachael
.
- Prev by Date: RE: Union sort
- Next by Date: RE: Union sort
- Previous by thread: RE: Union sort
- Next by thread: Re: Union sort
- Index(es):
Relevant Pages
|