How to sort two different date columns in mysql in descending order? -


can me on how sort 2 different date columns in mysql?

i have created query using table 2 different columns. first cert_date , other 1 special_training_date_from. want when execute query, output must this: cert_date , special_training_date_from columns must sorted in descending order. instance if cert_date '2012-01-03, 2012-07-07' , special_training_date_from '2011-05-03, 2013-08-01', output must be:

     2013-08-01,     2012-07-07,     2012-01-03,     2011-05-03 

this query i've used.

select training_title, cert_date, special_training_date_from  tabletraining  order cert_date + sptrain_from desc; 

the result correct everytime sort in ascending order, want sort in descending order , everytime put 'desc' keyword, result becomes incorrect.

you can put dates in single column use order by:

select training_title, thedate, ((select training_title, cert_date thedate, 'cert'        tabletraining       ) union       (select training_title, special_training_date_from, 'special'        tabletraining       )      ) t order thedate desc; 

edit:

if want distinct dates in 2 columns, use:

select distinct thedate ((select training_title, cert_date thedate, 'cert'        tabletraining       ) union       (select training_title, special_training_date_from, 'special'        tabletraining       )      ) t order thedate desc; 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -