在另一个表的一部分的第一个表上左联接 [英] Left join On first Table on Part of another Table

查看:71
本文介绍了在另一个表的一部分的第一个表上左联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我需要在数据库中建立一个Left联接,但是在Table1和Table2的一部分上.
在我的Table2中,我有一个用于语言的字段,例如:

表1(id,a,b,c,...)
表2(id,s,z,x,Lang,...)

Hi everyone.
I need to make one Left join in my database, but On Table1 And part of Table2.
In my Table2 i have One field for Language like this :

Table1(id,a,b,c,...)
Table2(id,s,z,x,Lang,...)

Select TUP.*,TUPI.Body,TUPI.Descriptions,TUPI.Keywords,TUPI.Name AS N'LangName',TUPI.SmallDesc From  [dbo].[TUniqueProduct]  TUP
Left Join TUniqueProductItems TUPI
On TUP.ProductID = TUPI.ProductPID
where [ProductGuID] = @ProductGuID AND [CurrentCount] > 0 AND TUP.ShopID = @ShopID And Lang = @Lang



但是我需要是否在Table2中没有任何项,其中Lang = @Lang On Table1.ID = Table2.ID,但是我可以看到Table1的字段.

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



But i need if there was not any items in Table2 where Lang = @Lang On Table1.ID = Table2.ID , however i can see fields of Table1.

Any suggestion?
Thanks in advance.

推荐答案

只需一点改动.
Just a minor change.
And (Lang = @Lang or Lang is null)


这篇关于在另一个表的一部分的第一个表上左联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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