这些都一样吗?

INNER JOIN dbo.ReportingLevels rl ON e.ei_CompanyID = rl.rl_CompanyId
    AND e.ei_Level = rl.rl_index
    AND EXISTS (SELECT * FROM @ReportingLevelId rlid
                WHERE rlid.[reportLevelName] = rl.[rl_name])
    AND EXISTS (SELECT * FROM @ReportingLevelId rlid
                WHERE rlid.[companyid] = rl.[rl_CompanyId])

这是第二个。
INNER JOIN dbo.ReportingLevels rl ON e.ei_CompanyID = rl.rl_CompanyId
    AND e.ei_Level = rl.rl_index
    AND EXISTS (SELECT * FROM @ReportingLevelId rlid
                WHERE rlid.[reportLevelName] = rl.[rl_name]
                  AND rlid.[companyid] = rl.[rl_CompanyId]))

我以为它们是相同的,但是当我使用类似的变体时,我得到了一个奇怪的结果。

最佳答案

不,他们不是。如果表@ReportingLevelId中存在rl_name和rl_CompanyId,则第一行将选择一行,但不一定在同一行中。第二个要求这些值出现在同一行中。

10-08 14:03