views:

20

answers:

3

Hi all,

Any idea on how to order the results of a MYSQL query by the sum of two columns rather than by a single column?

Select * FROM table ORDER BY (col1+col2) desc

I know that won't work., but I hope it conveys what I want to do fairly well.

Thanks!

A: 

Why not try before concluding it doesn't work? In point of fact, it does.

Matthew Flaschen
+1  A: 

The query you wrote should work just fine, you can have any expression in the ORDER BY clause.

Lukáš Lalinský
A: 

I think you should be able to do

SELECT *, col1+col2 as mysum ORDER BY mysum

Which is essentially the same as you already have

jfoucher