-2

I want to order the following two columns:

Column1(1) match Column2(1,2,3,4,5,6) and

Column1(2) match Column2(1,2,3,4,5,6)

Column1    Column2
=======    =======
1          1
1          2
1          12
2          1
1          4
1          5
2          2
2          3
2          6
2          5
1          6
2          4

What I expect is as follows:

Column1    Column2
=======    =======
1          1
1          2
1          4
1          5
1          6
1          12
2          1
2          2
2          3
2          4
2          5
2          6

Thanks you guys!

=====================================================

EDIT: edit column 2's data

user2761885
  • 327
  • 1
  • 7
  • 13
  • 2
    http://stackoverflow.com/questions/2051162/sql-multiple-column-ordering (close enough, please take time to search) , http://stackoverflow.com/a/2583848/2864740 , http://stackoverflow.com/questions/17091157/sorting-and-ordering-by-two-columns?rq=1 – user2864740 Dec 25 '13 at 05:37

1 Answers1

3

Just use the ORDER BY clause:

SELECT   colum1, column2
FROM     my_table
ORDER BY column1 ASC, column2 ASC
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • please see the edited table, column 2 is not ascending, how about this? I use order by column1 ASC, column2 ASC, the result I got is column 1 is ordered asc but column 2 not. – user2761885 Dec 25 '13 at 05:41
  • I figure out it, the reason is it order by the first digit, so I got the wrong result. – user2761885 Dec 25 '13 at 05:47