简体   繁体   English

合并不同表中的两列

[英]Merge two columns in different tables

I have two table, 我有两个桌子,

Project 项目

-----------------------
id  | name | created
-----------------------
1   | p1   | 2015-05-05
2   | p2   | 2015-04-29
3   | p3   | 2015-05-07

Task 任务

------------------------
id  | name   | created
------------------------
1   | t1     |2015-05-04
2   | t2     |2015-04-30
3   | t3     |2015-05-06

I want this table. 我要这张桌子。

Last Actions 最后动作

--------------------------
type |name    | created
--------------------------
p    | p3     | 2015-05-07
t    | t3     | 2015-05-06
p    | p1     | 2015-05-05
t    | t1     | 2015-05-04
t    | t2     | 2015-04-30
p    | p2     | 2015-04-29

p - project type and t - task type p-项目类型,t-任务类型

How can I get this data? 我如何获得这些数据?

Perhaps the easiest way would be union all 也许最简单的方法是union all

select * from
(
 select 'p' as type,
 name,
 created 
 from Project
 union all
 select 't' as type,
 name,
 created 
 from Task
)x
order by created desc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM