SQL连接和位置问题

时间:2018-07-25 21:21:42

标签: sql

当我运行以下查询时,我遇到了以下问题

SELECT ClientSubId,ClientType,ClientStatus,AddressLine1,AddressLine2,
  CityName,PostalCode,StateProvinceCode,
  ClientFirstName,ClientLastName, BillManagerName

FROM CLIENT
JOIN
CLIENTADDRESS
ON CLIENT.ClientIdent = CLIENTADDRESS.ReferenceIdent

JOIN 
CLIENTINDIVIDUAL
ON CLIENT.ClientIdent = CLIENTINDIVIDUAL.ClientIdent

JOIN
CLIENTPRACTICE
ON CLIENT.ClientIdent = CLIENTPRACTICE.ClientIdent

我正在返回与所有字段匹配的所有结果,女巫是正确的,但是当我在末尾应用where子句

WHERE
CLIENT.ClientIdSubId = '48079'

我没有结果。我对为什么我在应用Where子句时没有得到任何结果感到困惑,但是没有它,我得到了所有结果,而ID号就是这些结果的一部分。

Results without the WHERE

Results With the Where

2 个答案:

答案 0 :(得分:0)

您的查询非常简单。我只能看到两个可能的问题:

  1. 没有Option Explicit Public Sub SelectionTest() Dim selection As Variant Dim rng As Range Dim UsedRange As Variant Dim lastCell As Range Set selection = Application.selection Dim area As Range Debug.Print "selection columns " & selection.Columns.Count Dim finalRng As Range Dim finalArr As Variant For Each area In selection.Areas Debug.Print "single rng columns " & area.Columns.Count Set lastCell = area.Find(What:="*", After:=area.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _ xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False) Set lastCell = area.Find(What:="*", After:=area.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _ xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False) Debug.Print lastCell Next End Sub 等于CLIENT的{​​{1}}。

  2. 有一个符合该条件的ClienIdSubId,但是'48079'CLIENTCLIENTADDRESS中没有匹配的行。由于您正在使用 INNER JOINS

  3. ,请确保每个表上都有匹配的行。

答案 1 :(得分:0)

很抱歉,我有正确的查询ClientIdSubId应该是ClientSubId。而不是ClientIdSubId。