简体   繁体   中英

How to union two tables A and B but B has one column missing while the result should have all the columns?

I have A table (P1, P2, P3) and B table (P1, P2), now I want to union them together. I know I can do something like

SELECT P1, P2 FROM A UNION SELECT P1, P2 FROM B

to merge all the rows. But in the result I have to get P3 too and for rows coming from B P3 should be null, how can I do this?

(SELECT P1, P2,P3 FROM A)
UNION ALL
(SELECT P1, P2,null FROM B)

check http://sqlfiddle.com/#!9/32f84/2

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