连接包含空值的表列时出现问题. [英] Problem while joining table columns containing null values.

查看:99
本文介绍了连接包含空值的表列时出现问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我的sql查询中,我必须联接6个以上的表才能选择一条记录.在此,某些表包含空值.由于此空值,我无法检索任何记录.

例如,

我的查询看起来像这样

Hi
In my sql query, I have to join more than 6 tables to select a record. In this some of the tables contains null values. Because of this null values i couldn''t retrieve any records.

For ex,

My query looks like this

Select columns from table1 join table2 on tabl1.c1 = table 2.c join table3 on table1.c2 = table3.c join table4 on table1.c3 = table4.c join table5 on table1.c4=table5.c  ........... where id=value

像这样.


在这里
---->在此行中在table1.c3上加入table4 = table4.c

table1.c3为空...所以我无法选择记录.

我的问题是,如果该列为空,则只需使用该记录返回空值.

like this.


Here
----> In this line join table4 on table1.c3 = table4.c

table1.c3 is null... So I am unable to select records.

My question is If that column is null then just return null values with that records.

How can i solve it?

推荐答案

Left outer join用于table4 on table1.c3 = table4.c,则将检索表table1中的所有记录.
谢谢
Ashish
Use Left outer join for table4 on table1.c3 = table4.c, then all the records from table table1 will be retrieved.

Thanks
Ashish


在这种情况下,您需要使用外部联接.外部联接返回表中的行,即使联接表中没有对应的行也是如此.

外部联接可以是左外部联接,也可以是右外部联接,具体取决于您列出表的顺序.

请查看 SQL联接 [ SQL左联接 [ ^ ]和 SQL权利加入 [
You need to use an outer join in this kind of situation. Outer join returns rows from a table even if it has no corresponding rows in the joined table.

The outer join can be a left outer join or a right outer join depending on the order you list the tables.

Have a look at all of the join examples in SQL Joins[^], especially SQL LEFT JOIN[^] and SQL RIGHT JOIN[^]


这篇关于连接包含空值的表列时出现问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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