我在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)
答案 0 :(得分:2)
使用UNION
或UNION ALL
:
SELECT `date`
FROM
(
SELECT death AS `date` FROM tablename
UNION ALL
SELECT birth FROM tablename
) AS t
ORDER BY `date`;