SQL - Sortingproblem

  • Thread starter Thread starter Joergen Bondesen
  • Start date Start date
J

Joergen Bondesen

Hi NG



I have a table: SE_Data. All Fields are text.



I have two queries on the table: SE_Data





Q_CM

Crit: <"26999" Or >"40000" And <"44999" Or >"62000" And <"62499"

Sort: Ascending (Zip code)



Q_Po

Crit: Between "26999" And "40000" Or Between "44999" And "62000" Or

Sort: Ascending (Zip code)





When I run both queries, data is ascending.



My union query, Q_CM_Po:






SELECT Zip, City

FROM Q_CM



UNION ALL



SELECT Zip, City

FROM Q_Po;





where Q_CM is ascending but Q_Po does not start with the correct zip code,

it begins with '28531' ascending to '34236'

and then begin '27033' ascending to '28437' followed by '34250' and then
ascending fine.



Why this problem, and what can I do?



--



Best regards from

Joergen Bondesen
 
A union query is going to ignore any sorting that has taken place outside
the union query.

SELECT Zip, City
FROM Q_CM
UNION ALL
SELECT Zip, City
FROM Q_Po
ORDER BY Zip

If you want to the data sorted separately then you would need to do
something like
SELECT Zip, City, "A" as SortOn
FROM Q_CM
UNION ALL
SELECT Zip, City, "B"
FROM Q_Po
ORDER BY SortOn, Zip


--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
Back
Top