Forum Moderators: coopster

Message Too Old, No Replies

Howto Sort Results Vertically?

         

HoboTraveler

7:59 am on May 3, 2008 (gmt 0)

10+ Year Member



Hi All,

I need to sort the contents of two tables. PHP is the frontend and MySQL the backend.

I've read through MySQL's JOIN which did not produce the desired results.

Ideas welcome.

Table 1:
id name occupation
2 foobar manager
3 johnny CEO

Table2:
id name occupation
1 mike tech
5 foo doctor

Sorted Results of Table 1 and Table 2 Descending:

id name occupation
5 foo doctor
3 johnny CEO
2 foobar manager
1 mike tech

[edited by: HoboTraveler at 8:00 am (utc) on May 3, 2008]

coopster

3:42 pm on May 3, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you considered a UNION?

HoboTraveler

6:01 pm on May 3, 2008 (gmt 0)

10+ Year Member



Doesn't seem like a UNION can sort. I am able to execute two queries through an UNION. The sort seems to be an issue.

Do post an example if it works..

TIA

coopster

6:09 pm on May 3, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have a closer look at the docs
[dev.mysql.com...]

(SELECT a FROM t1 WHERE a=10 AND B=1) 
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2)
ORDER BY a LIMIT 10;

There are good explanations on how to do so on the manual page.