SQL UNION按日期排序最新到最旧

时间:2015-09-18 17:21:49

标签: mysql sql-order-by union

我应该如何播放此查询以按date_scheduled排序从最新到最早提前感谢。

$query = "(SELECT ref_num, event_type, time_scheduled, date_scheduled, date_apply as a, time_apply as t, m_lname as b, m_fname as c, f_fname as d, `read` as r,  'wedding' as type FROM wedding) 
           UNION
           (SELECT ref_num, event_type, time_scheduled, date_scheduled, date_apply as a, time_apply as t, c_lname as b, c_fname as c, c_mname as d, `read` as r, 'baptism' as type FROM baptism) 
           ORDER BY date_scheduled DESC LIMIT 15
           ";

1 个答案:

答案 0 :(得分:-1)

试试这个......

$query = "SELECT ref_num, event_type, time_scheduled, date_scheduled, a, t, b, c, d, r, type from (SELECT ref_num, event_type, time_scheduled, date_scheduled, date_apply as a, time_apply as t, m_lname as b, m_fname as c, f_fname as d, `read` as r,  'wedding' as type FROM wedding) 
           UNION
           (SELECT ref_num, event_type, time_scheduled, date_scheduled, date_apply as a, time_apply as t, c_lname as b, c_fname as c, c_mname as d, `read` as r, 'baptism' as type FROM baptism) as tmp
           ORDER BY date_scheduled DESC LIMIT 15
           ";