mysql - Does the order matter in ORDER BY clause? -


in sql order by clause, table in example.

[  -  b   -   c   -  d ] -------------------------- [ x  -  1   -     -  e ] [ y  -  2   -   k   -  f ] [ z  -  3   -   m   -  g ] 

if wrote clause following

order asc, b desc, c desc, d asc 

is there difference if changed order of columns somehting like

order d desc, c desc, b asc, asc 

or work same , doesn't make difference since pick exact order columns d desc, c desc, b asc, asc same order asc, b desc, c desc, d asc in difference order?

order asc, b desc, c desc, d asc means that

  • first order in ascending order
  • then order b in descending order
  • then order c in descending order
  • at last order d in ascending order

in example not matter because values same in below example senses such

example inordered list suach as;

|  |  b  |  c  | d  | ----------------------- | 10 |  5  |  2  |  7 |  | 10 |  3  |  1  |  7 |  | 5  |  5  |  6  |  3 |  | 4  |  2  |  5  |  3 |  | 5  |  4  |  6  |  3 |     | 3  |  5  |  9  |  4 | | 3  |  6  |  6  |  4 |  | 5  |  5  |  6  |  3 |  | 4  |  2  |  5  |  3 |  | 5  |  4  |  6  |  3 |     | 3  |  5  |  1  |  4 | | 3  |  6  |  2  |  4 |  

and order d asc, asc, b desc, c desc;

 |   |  b |  c | d  |  -----------------------  |  4  |  2 |  5 |  3 |  |  4  |  2 |  5 |  3 |  |  5  |  5 |  6 |  3 |  |  5  |  5 |  6 |  3 |  |  5  |  4 |  6 |  3 |  |  5  |  4 |  6 |  3 |  |  3  |  6 |  6 |  4 |  |  3  |  6 |  2 |  4 |  |  3  |  5 |  9 |  4 |  |  3  |  5 |  1 |  4 |  |  10 |  5 |  2 |  7 |  |  10 |  3 |  1 |  7 | 

then ordered after order asc, b desc, c desc, d asc is

 |  |  b |  c |  d |    --------------------  | 3  |  6 |  6 |  4 |   | 3  |  6 |  6 |  4 |   | 3  |  6 |  2 |  4 |   | 3  |  5 |  9 |  4 |   | 3  |  5 |  1 |  4 |   | 4  |  2 |  5 |  3 |   | 4  |  2 |  5 |  3 |   | 5  |  5 |  6 |  3 |   | 5  |  5 |  6 |  3 |   | 5  |  4 |  6 |  3 |   | 5  |  4 |  6 |  3 |   | 10 |  5 |  2 |  7 |   | 10 |  3 |  1 |  7 | 

for order d desc, c desc, b asc, asc , result that

 |   |  b |  c |  d |   |  10 |  5 |  2 |  7 |  |  10 |  3 |  1 |  7 |  |  3  |  5 |  9 |  4 |  |  3  |  6 |  6 |  4 |  |  3  |  6 |  2 |  4 |  |  3  |  5 |  1 |  4 |  |  5  |  4 |  6 |  3 |  |  5  |  4 |  6 |  3 |  |  5  |  5 |  6 |  3 |  |  5  |  5 |  6 |  3 |  |  4  |  2 |  5 |  3 |  |  4  |  2 |  5 |  3 | 

please play given example order commands here http://rextester.com/lkbrk29917


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -