合并不同表中的两列

时间:2022-10-22 20:19:46

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?

我怎样才能获得这些数据?

1 个解决方案

#1


Perhaps the easiest way would be 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

#1


Perhaps the easiest way would be 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