临时组合SQL表 [英] Temporary combine SQL tables

查看:81
本文介绍了临时组合SQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何组合这样的sql表?



表1:

How do I combine sql tables like this?

Table1:

|first  |last         |hair    |
|peter  |Jackson      |brown   |





表2:



Table2:

|pet |hair     |
|dog |grey     |
|cat |         |







产出表:




Output table:

|first    |last         |hair    |pet  |
|peter    |Jackson      |brown|        |
|         |             |grey    |dog  |
|         |             |        |cat  |





它不必实际创建第三个表,只需创建一个临时可选择的表。

[edit]已添加代码块 - OriginalGriff [/ edit]



我尝试过:



我还没有尝试过任何东西。

我知道有一些sql加入命令,但如果它不对,我不想这样做一个。



It doesn't have to actually create the third table just create a temporary selectable one.
[edit]Code block added - OriginalGriff[/edit]

What I have tried:

I haven't tried anything yet.
I know there are some sql joining commands, but I don't want to go this way if it isn't the right one.

推荐答案

尝试一个UNION:

Try a UNION:
SELECT first, last, hair, null AS pet FROM Table1 UNION ALL SELECT null, null, hair, pet FROM Table2


这篇关于临时组合SQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆