[AccessD] Union Query with ORDER BY

Gustav Brock gustav at cactus.dk
Fri Jul 18 05:13:44 CDT 2003


Hi Paul

Great help, I know, but this "works a treat" for me in A97 ...

/gustav


> I'm trying to write a UNION SQL query below to get the 5 closest zip
> codes in both directions.  To do this, I need to put an ORDER BY
> clause to get the closest ones in each direction.  Running the query
> separately without UNION everything works fine, however, using the
> UNION creates a syntax error which has to do with ORDER BY.  

> Any ideas?  I would like to keep it as a UNION but worst scenario would be to run two recordsets...

> Thanks,
> Paul Millard
> San Jose, CA


> SELECT 
> TOP 5
> ZipCode, Svc, SvcMiles
> FROM
> tblSvcToZipMiles
> WHERE
> ZipCode<'95022' 
> ORDER BY ZipCode DESC
> UNION
> SELECT 
> TOP 5
> ZipCode, Svc, SvcMiles
> FROM
> tblSvcToZipMiles
> WHERE
> ZipCode>'95022'
> ORDER BY ZipCode ASC



More information about the AccessD mailing list