sort with order by first and then second
orderby clause of mysql may be used with one or more columns if we want to sort first column with some order and then the second column with some other order if the values or fist column are in duplicate. This clause used as :
select * from <Table Name> order by <First Column>,<Second Column>.......,<Nth Column>
Sample Table (four column in a table, select all table values
mysql> select * from orderingRecords; +-------+------+------+------+ | Basic | DA | TA | RA | +-------+------+------+------+ | 1000 | 1200 | 1300 | 1400 | | 900 | 1400 | 1400 | 1400 | | 1600 | 900 | 1300 | 1700 | | 1600 | 1800 | 1300 | 1100 | +-------+------+------+------+ 4 rows in set (0.00 sec)
Sort RA column in ascending order.
mysql> select * from orderingRecords order by RA; +-------+------+------+------+ | Basic | DA | TA | RA | +-------+------+------+------+ | 1600 | 1800 | 1300 | 1100 | | 1000 | 1200 | 1300 | 1400 | | 900 | 1400 | 1400 | 1400 | | 1600 | 900 | 1300 | 1700 | +-------+------+------+------+ 4 rows in set (0.00 sec)
As you can see values of RA 1400, 1400 are same, so we want to sort Basic column values in ascending order wherever values of RA(column) are similar. Indicated by following image :