"Ed Reed" <[EMAIL 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
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL 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/[EMAIL PROTECTED]

Reply via email to