order by date format with union in mysql -
i have used union order by, in resultant table date format not ordering.
( select date_format(date_1, '%m/%d/%y') first_date, null second_date, col_2, col_3, col_4 table1 date_1 !='' ) union ( select null first_date , date_format(date_2, '%m/%d/%y') second_date, col_2, null col_3, col_4 table1 date_2 !='' ) order date_1 desc, date_2 desc;
with above able retrieve records dates not ordered. help!
excerpt mysql reference
if column sorted aliased, order clause must refer alias, not column name.
( select date_format(date_1, '%m/%d/%y') first_date, null second_date, col_2, col_3, col_4 table1 date_1 !='' ) union ( select null first_date , date_format(date_2, '%m/%d/%y') second_date, col_2, null col_3, col_4 table1 date_2 !='' ) order first_date desc, second_date desc;
Comments
Post a Comment