MySQL 'ORDER BY' from 2 columns but in alp order over both

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Finally, I found the easiest and best way to do it....

Code: Select all

mysql>  select company from test1
    ->  union
    ->  select name from test1
    ->  order by 1 asc
    ->  ;


+-----------+
| company   |
+-----------+
| gg        |
| google    |
| microsoft |
| msft      |
| yahoo     |
| yh        |
+-----------+
6 rows in set (1.70 sec)
Post Reply