MySQL - order by two columns with condition -


i have data in mysql table. need order results condition:

  • if effective_to null, show first , order effective_from desc
  • if effective_to not null, order effective_to desc

my data

name            effective_from      effective_to person 01       1999-04-01          1999-05-31 person 02       1999-04-01          2000-07-06 person 03       1999-04-01          2000-09-25 person 04       1999-04-01          2000-09-25 person 07       1999-04-01          2000-09-25 person 05       2013-04-29          null person 08       2010-06-17          2012-09-27 person 09       2010-12-02          2012-09-27 person 10       2017-02-10          null person 11       2017-02-10          null person 12       1999-04-01          2000-07-06 person 13       2011-04-28          2015-10-06 person 05       2013-04-29          2017-02-15 person 06       2015-09-22          2017-02-15 person 06       2015-09-22          2017-02-10 

i need results order

name                effective_from  effective_to                                                 person 11       2017-02-10          null person 10       2017-02-10          null person 05       2013-04-29          null person 06       2015-09-22          2017-02-15 person 05       2013-04-29          2017-02-15 person 06       2015-09-22          2017-02-10 person 13       2011-04-28          2015-10-06 person 09       2010-12-02          2012-09-27 person 08       2010-06-17          2012-09-27 person 07       1999-04-01          2000-09-25 person 03       1999-04-01          2000-09-25 person 04       1999-04-01          2000-09-25 person 12       1999-04-01          2000-07-06 person 02       1999-04-01          2000-07-06 person 01       1999-04-01          1999-05-31 

how this?

(posted on behalf of op).

i resolve problem this:

order `effective_to` not null asc, `effective_to` desc,     `effective_to` null, `effective_from` desc; 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -