从两个表中获取相同列的值

时间:2015-10-23 09:46:14

标签: sql postgresql

我有这张桌子

select id, name from projects;
id |    name     
---+-------------
 1 | TestProject
 2 | testProject
 3 | test
 4 | sdaf
 5 | P0500

和此表(work_packages)

 select * from work_packages;
 id |  name   | started_on | finished_on | person_month | parent_id | project_id
----+---------+------------+-------------+--------------+-----------+------------+---------
  7 | AP00001 | 2015-10-23 | 2015-10-31  |            0 |         1 |          1 |        
  8 | d       | 2015-10-23 | 2015-10-31  |            0 |         7 |          1 |       

我需要projectswork_packages

中的此表格
name         
---------------
 P0500
 AP00001
 d

1 个答案:

答案 0 :(得分:0)

尝试:

select name from projects
union
select name from work_packages;

您可以在条件中过滤结果,例如

select name from projects
where id >= 5
union
select name from work_packages;