| Mailing List | | Home | | MySQL General - General MySQL discussion | | MaxDB - Everything about MaxDB, formerly known as SAP DB | | MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP | | Java Help - Mostly related to the MySQL Connector/J driver | | ODBC - ODBC with the MySQL Connector/ODBC driver | | Perl - Perl support for MySQL with DBI and DBD::mysql | | MySQL++ - Programming with the C++ API to MySQL |
|
|
  | |  | Union Query Sorting | Union Query Sorting 2004-03-13 - By Egor Egorov
Back "Ed Reed " <ereed@(protected) > wrote:
> Can anyone tell me how to sort the combined results of a Union query?
> Right now I have a Group By and Order By in both of my queries that make
> up my Union but the results are grouped and sorted within the two
> queries but not between the two queries. The example below demonstrates
> my problem. In the results the first four people are employees and the
> last three are consultants
>
> (Select Name From Employee Group By Name Order By Name)
> Union (Select Name From Consultant Group By Name Order By Name);
>
> Results,
>
> A Person
> John Doe
> Paul Dude
> Ronald McDonald
> Beer Drinker
> Mayor McCheese
> Pizza Eater
>
> What I want is both queries grouped and sorted together. So the Results
> should look like this,
>
> A Person
> Beer Drinker
> John Doe
> Mayor McCheese
> Paul Dude
> Pizza Eater
> Ronald McDonald
>
Just add ORDER BY to the end of statement:
(SELECT .... )
UNION
(SELECT .... )
ORDER BY Name;
http://www.mysql.com/doc/en/UNION.html
--
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.net
http://www.ensita.net/
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Egor Egorov
/ /|_/ / // /\ \/ /_/ / /__ Egor.Egorov@(protected)
/_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.net
<___/ www.mysql.com
--
MySQL General Mailing List
For list archives:
http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/mysql?unsub=mysql
@(protected)
|
|
 |