Sol Sol - 2 months ago 5
SQL Question

How to order 2 columns, both ascending base on the other column?

SELECT column1,
column2,
FROM table
ORDER BY `table`.`column1` ASC
AND `table`.`column2` ASC


You can't do this code as written above, but I would like to have column1 show 1,2,3 then it order column2 1,2,3 based on column1. How do you do this?

column1 column2
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

Answer

You can write as following: column1 is enough in the order by:

Select column1, column2 
from table
order by column1, column2
Comments