在任何情况下显示我的左联接的左部分 [英] Show Left part of my Left join In any case

查看:77
本文介绍了在任何情况下显示我的左联接的左部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我有两个表,我需要在左边加入它们.但是在第二个表中,我有一个语言字段,我将其命名为"Lang",就像这样:

表1:(id,a,b,c,...)
Table2:(id,Table1ID,a,b,Lang,...)

我需要使用任何语言进行左联接,但是我需要是否在Table2中没有任何行,或者即使在Table2中也没有行,但是对于另一种语言,无论如何我都需要Table1字段.

我现在有这个:

Hi every one.

I have two Tables, that i need join them in left. But in second Table i have a Language field that i named it "Lang" , Like this :

Table1 : (id,a,b,c,...)
Table2 : (id,Table1ID,a,b,Lang,...)

I need left join in any language, but i need if there was not any row in Table2, or EVEN there was rows in Table2 but for another languages but I NEED Table1 fields in any case.

I have this now :

Select * From  [dbo].[TUniqueProduct]  TUP
Left Join TUniqueProductItems TUPI
On TUP.ProductID = TUPI.ProductPID
where TUP.ProductGuID = 1000 AND  (Lang = 1 OR Lang IS NULL)
order by RowOrder, ProductID DESC



当表2中的此lang行或此ID没有任何行时,它向我显示了左部分.
但是,如果有另一种语言的行,它就不能向我显示左侧.在这种情况下,我需要左侧部分,而右侧部分字段则为null.

有什么建议吗?
在此先感谢.



It show me left part when there is row in Table2 for this lang,or there is not any row for this ID.
BUT it can not show me left side if there is rows for another languages. in this case i need left part and null for right part fields.

Any suggestion?
Thanks in advance.

推荐答案

查询工作正常.如果需要所有语言的结果,但显示为null,则需要更改连接条件On TUP.ProductID = TUPI.ProductPID AND (Lang = 1 OR Lang IS NULL)
The query works as expected. If you need result for all the languages, but shown as null, then you need to change the join condition On TUP.ProductID = TUPI.ProductPID AND (Lang = 1 OR Lang IS NULL)


这篇关于在任何情况下显示我的左联接的左部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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