order by field in a union query

109bow

Registered User.
Local time
Today, 18:10
Joined
Oct 24, 2007
Messages
141
I have 8 queries 110, 120, 130, 140, 140s, 130s, 120s and 110s which I have combined these using a union query, however the union query returns results based on the first column of the queries. I need the query to return the results in the order above.
the first column of each query is called car_no,
query 110 the car_no column will have a record of 11004,
query 120 will have 12004,
query 130 will have 13004
query 140 will have 14004
query 140s will have 14003
query 130s will have 13003
query 120s will have 12003
query 110s will have 11003.
how do I get the union query to return the records in order of car_no listed above rather than getting the order 11003, 11004, 12003, 12004, 13003, 13004, 14003 + 14004.
Thanks in advance :banghead::banghead::banghead:


but queries ending with s the car_no record will end in an odd number
 
Maybe you could make one union query of 110, 120, 130, and 140 and make a query of this union query that is sort in ascending order on car_no. Let's call that Query1. Then make another union query of 140s, 130s, 120s and 110s and make a query of that union query that is sorted in descending order on car_no. Let's call that Query2. Then make a union query of Query1 and Query2.
 
thanks for your reply, how do I get a union query to sort car_no in descending, as this could well solve my problem,
thanks
 
Make your union query. (QnUnionQry)
Then make a sort query that uses the union query and sorts it.

Select * from QnUnionQry order by CarNo
 
thanks for your reply, how do I get a union query to sort car_no in descending, as this could well solve my problem,
thanks

  1. On the CREATE tab click Query Design
  2. In the Show Table dialog click on the Queries tab
  3. Select the union query in question and click Add
  4. Double click on each field to put it in the grid
  5. In the car_no field select the sort order you wish
  6. Save the query
 

Users who are viewing this thread

Back
Top Bottom