Ok i have this in my database as example
id | x | y | z | status | statusb
1 | 20 | 12 | 13 | 1 | 2
2 | 40 | 32 | -- | 3 | 2
3 | 50 | 31 | 15 | 2 | 1
im doing a select like
"select * FROM table ORDER BY GREATEST(COALESCE(x, 0),COALESCE(y, 0), COALESCE(z, 0)) DESC"
And the echo inside a for each.. is like
if (status==1) { echo $row_x style1}
if (status==2) { echo $row_x style2}
if (status==3) { echo $row_x style3}
if (statusb==1) { echo $row_y style4}
if (statusb==2) { echo $row_y style5}
I get something like
id3 - x50 style2
id3 - y31 style4
id2 - x40 style3
id2 - y32 style5
id1 - x20 style1
id1 - y12 style5
What i need is
id3 - x50 style2
id2 - x40 style3
id2 - y32 style5
id3 - y31 style4
id1 - x20 style1
id1 - y12 style5
Thanks to Chinnu R for the fast answer the problem is that y or x can have 0 (not null) as default when the col is created the value is 0 unless the user update that..
So my problem is 0 affecting the query using the answer
ORDER BY x DESC, y DESC, z desc
id | x | y | z | status | statusb
1 | 20 | 12 | 13 | 1 | 2
2 | 40 | 0 | -- | 3 | 2
3 | 50 | 31 | 15 | 2 | 1