MySQL Forums
Forum List  »  Newbie

Re: order by max of two columns
Posted by: Ramalingam Chelliah
Date: September 07, 2004 06:53AM

Hi,
If you like to order records in table by Max( column1,Column2)

Try this ..

mysql> SELECT * from
tablename
ORDER BY ABS(Column1-Column2);

Hope this helps...

Regards,
Ram.

PS: My Trial

mysql> select * from Max2C;
+----+------+------+
| ID | No1 | No2 |
+----+------+------+
| 1 | 12 | 15 |
| 2 | 15 | 11 |
| 3 | 10 | 12 |
| 4 | 1 | 20 |
+----+------+------+
4 rows in set (0.00 sec)


mysql> select No1,No2 from Max2C
-> ORDER BY ABS(No1-No2);
+------+------+
| No1 | No2 |
+------+------+
| 10 | 12 |
| 12 | 15 |
| 15 | 11 |
| 1 | 20 |
+------+------+
4 rows in set (0.00 sec)





We Learn the Most When we have to Invent

Options: ReplyQuote


Subject
Written By
Posted
September 06, 2004 08:46AM
Re: order by max of two columns
September 07, 2004 06:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.