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
Subjects
mysql openssl Question
mysql:it 's a db not a dbms how it 's possible?!
Does the binary log enabling affect the MySQL performances?
Strange behavior, Table Level Permission
FULLTEXT query format question
Preventing Duplicate Entries
Comparing and writing out BLOBS
Executing MySQL Commands From Within C Program
Can 't access mysql after kernel upgrade
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Downgrade Mysql from 4 to 3 23
MySQL Cluster Software
mysql test 4 1 fails with the gis test
ERROR 2002: Can 't connect to local MySQL server through socket
Getting Identity after INSERT
Update one field with more fields from another table
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
mysql have same function mthod as Oracle decode()
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
Union Query Sorting

Union Query Sorting

2004-03-13       - By Egor Egorov

 Back
Reply:     1     2     3     4     5  

"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)