简体   繁体   中英

How to find a specific row between two tables by a common column in postgresql?

I'm using PostgreSQL and I have two tables like below:

table1:
id   title  content  mail_number

table2:
id   title   mail_date   mail_number

now in my codes, I have a special mail_number, and I want to find the row that has my mail_number! I want something like:

select * from table1 OR table2 where mail_number = (my_number)

Well, you can do something like this:

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>;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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