将2个mysql日期列混合为一个并按顺序排列

时间:2013-12-28 12:53:58

标签: mysql sql join

我在MySQL中有一个表“USER”,有些列是“ID”,“名称”,“出生”和“死亡”......出生和死亡保存日期值。

我想显示出生和死亡,然后按日期ASC排序。

以下是我拥有的和我需要的一个例子。

column Birth:
1-2-99
2-2-99

column Death:
1-1-99
2-3-99

desired result from a query:
1-1-99 (from death col)
1-2-99 (from Birth col)
2-2-99 (from Birth col)
2-3-99 (from death col)

示例显示为(DD,MM,YY)

1 个答案:

答案 0 :(得分:2)

使用UNIONUNION ALL

SELECT `date`
FROM
(
    SELECT death AS `date` FROM tablename
    UNION ALL
    SELECT birth           FROM tablename
) AS t
ORDER BY `date`;