Akim
Akim

Reputation: 136

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

How can I get this data?

Upvotes: 0

Views: 55

Answers (1)

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44844

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

Upvotes: 2

Related Questions