在任何情况下显示我的左联接的左部分

编程入门 行业动态 更新时间:2024-10-24 12:22:39
本文介绍了在任何情况下显示我的左联接的左部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好. 我有两个表,我需要在左边加入它们.但是在第二个表中,我有一个语言字段,我将其命名为"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)

更多推荐

在任何情况下显示我的左联接的左部分

本文发布于:2023-11-29 00:57:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644644.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:情况下

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!