如何通过PostgreSQL中的公共列在两个表之间找到特定行?

时间:2018-06-25 16:08:02

标签: sql postgresql select

我正在使用PostgreSQL,并且有两个如下表:

mesh.geometry.boundingSphere.center.set( x, y, z );
mesh.geometry.boundingSphere.radius = radius;

现在在我的代码中,我有一个特殊的mail_number,我想找到包含我的mail_number的行! 我想要类似的东西:

table1:
id   title  content  mail_number

table2:
id   title   mail_date   mail_number

1 个答案:

答案 0 :(得分:3)

好吧,您可以执行以下操作:

select id, title, content, NULL as mail_date, mail_number
from table1
where mail_number = <my_number>
union all
select id, title, NULL as content, mail_date, mail_number
from table1
where mail_number = <my_number>;