I have a table that listed six unique numbers in a row, on their specified columns:
id | n1 | n2 | n3 | n4 | n5 | n6 |
---|---|---|---|---|---|---|
1 | 44 | 11 | 32 | 14 | 28 | 19 |
How I can use MySQL to get the row values in an ascending order?
id | n1 | n2 | n3 | n4 | n5 | n6 |
---|---|---|---|---|---|---|
1 | 11 | 14 | 19 | 28 | 32 | 44 |
Thank you!
I tried ORDER BY FIELD(), subqueries and concatenation, but nothing works.
SELECT aa.*,
(SELECT CONCAT(n1,",",n2,",",n3,",",n4,",",n5,",",n6) FROM table bb WHERE bb.id=aa.id ORDER BY FIELD(n1,n2,n3,n4,n5,n6) asc) AS conc
FROM table aa
WHERE aa.id=1
I know is a childish approach, but I have no idea how to get the right result.
2
Answers
Try this, but you should care if they have the same number