大家好. 我有两个表,我需要在左边加入它们.但是在第二个表中,我有一个语言字段,我将其命名为"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)
更多推荐
在任何情况下显示我的左联接的左部分
发布评论