从2个Tbal中选择SQL [英] SQL Selection from 2 Tbales

查看:74
本文介绍了从2个Tbal中选择SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有2个表Table1和Table2.
表1具有(A,B,C)列.表2具有(A,B,D).
表1具有52个Rceords.
表2有5条记录.表1中存在这5条记录.

现在我要从两个表中选择A,B,C,D.对于不存在的值,应显示为null.

例子:

A B C D
1 10空25
2 10 85空.

请帮助我.

问候,
Prasad

Hi All,

I have 2 tables Table1 and Table2.
Table1 have (A,B,C) columns. Table2 have (A,B,D).
Table1 Having 52 Rceords.
Table2 Having 5 records. These 5 are records are exist in Table1.

Now i want to select A,B,C,D from both tables. for non existing values it should show null.

example :

A B C D
1 10 null 25
2 10 85 null.

Please help me on this.

Regards,
Prasad

推荐答案

您好,我想下面的代码应该可以满足您的要求.

Hi, at a guess I believe the code below should do what you require.

SELECT
    t1.A
   ,t1.B
   ,t1.C
   ,t2.D
FROM
   Table1 t1
   LEFT OUTER JOIN Table2 t2 ON
      t1.A = t2.A AND
      t1.B = t2.B



我通常在表上使用左外连接",我希望从
中得到空值
因此,猜测除了5个结果外,所有D都将为NULL.

希望对您有帮助



I usually use a Left Outer Join onto the table I want a null to come from

So at a guess you will have NULL in D for all but 5 results.

Hope that helps


这篇关于从2个Tbal中选择SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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