如果JOINED值为null,则LEFT Join不会从主表中提取记录

时间:2019-05-30 18:20:38

标签: sql ssms

说我有一个像这样的tableA:

 ID         Name         IssueID
 1          Bob          2
 2          John         Null

我有一个名为tblRef的参考表,其中包括以下列:

 IssueID       IssueDesc
 2             Not Completed
 3             Completed

我的查询看起来像这样

Select a.Id,a.Name, I.IssueDesc from tableA a Left Join tblRef I on a.issueId = 
I.IssueDesc where IssueID not in (2)

如果执行此操作,则看不到tableA中IssueID为NULL的记录,是否有任何方法可以将其提取?或者更确切地说,为什么它不收集记录?

1 个答案:

答案 0 :(得分:4)

This will solve your problem... 1.Download PIG ->http://mirrors.estointernet.in/apache/pig/pig-0.16.0/ 2.Set properties-> PIG_HOME=C:\Users\lenovo\Downloads\pig-0.16.0\pig-0.16.0 path=C:\Users\lenovo\Downloads\pig-0.16.0\pig-0.16.0\bin PIG_CLASSPATH=C:\Users\lenovo\Downloads\hadoop-2.7.3\hadoop-2.7.3\etc\hadoop(Where core-site.xml,mapred-site.xml are present) 3. ->open the file pig.cmd(From bin directory of PIG) ->look for the line set HADOOP_BIN_PATH=%HADOOP_HOME%\bin ->replace this with set HADOOP_BIN_PATH=%HADOOP_HOME%\libexec 4.Now in command prompt give->pig `enter code here` “失败”几乎所有比较。实际发生的结果是NULL,并且行被过滤掉了。

在SQL Server中,您需要对此进行明确测试:

NULL

请记住,where IssueID not in (2) OR IssueID is null 的语义通常具有“未知”值而不是“缺失”值的含义。当您拥有NULL时,语义是“不在(2)中”。结果为“未知”,因为值可以为2。