SQL – Order by (Sorting)

Spread the love

Order by – it sorts the  values ascending and descending, default is ascending if not specified

Table Brand

S.NOPRODUCTMONTHYEAR
1NIKEDEC2016
2REEBOKJAN2014
3FILAFEB2017
4PUMAJAN2015
5REEBOKFEB2016
6FILAMAR2015

 

Sort Product A-Z and Year Largest to Smallest

Select [S.No], Product , Month , Year from Brand
Order by Product Asc , Year Desc

Result

S.NOPRODUCTMONTHYEAR
3FILAFEB2017
6FILAMAR2015
1NIKEDEC2016
4PUMAJAN2015
5REEBOKFEB2016
2REEBOKJAN2014