第二个子SELECT语句在UNION中未返回值。

huangapple go评论62阅读模式
英文:

Second Sub-SELECT statement not returning value with UNION

问题

为什么这个查询...

SELECT DISTINCT [COS_JobTitle] AS 'Name'
FROM (
    SELECT [COS_BpsID] AS [COS_BpsID], [COS_JobTitle] AS [COS_JobTitle]
    FROM [CacheOrganizationStructure]
    WHERE [COS_AccountType] = 1

    UNION
        
    SELECT WFD_AttChoose3 AS WFD_AttChoose3, NULL
    FROM WFElements
    WHERE WFD_ID = 53584
) AS nnn

ORDER BY 'Name'

...没有返回第二个子查询语句的值?

SELECT WFD_AttChoose3 AS WFD_AttChoose3, NULL
    FROM WFElements
    WHERE WFD_ID = 53584

一旦我修改整个查询,省略每个子查询语句的第二列,它就能如预期般工作,即, [COS_JobTitle] AS [COS_JobTitle],NULL

英文:

Why does this query...

SELECT DISTINCT [COS_JobTitle] AS 'Name'
FROM (
    SELECT [COS_BpsID] AS [COS_BpsID], [COS_JobTitle] AS [COS_JobTitle]
    FROM [CacheOrganizationStructure]
    WHERE [COS_AccountType] = 1

    UNION
        
    SELECT WFD_AttChoose3 AS WFD_AttChoose3, NULL
    FROM WFElements
    WHERE WFD_ID = 53584
) AS nnn

ORDER BY 'Name'

...not return the value from the second sub-SELECT statement?

SELECT WFD_AttChoose3 AS WFD_AttChoose3, NULL
    FROM WFElements
    WHERE WFD_ID = 53584

Once I amend the entire query to omit the second column for each sub-SELECT statement query it works as expected, i.e. , [COS_JobTitle] AS [COS_JobTitle] And , NULL

答案1

得分: 0

事实证明,一切都可以在一组不同的表格中运行。然而,并没有继续调查这个问题。

英文:

Turned out everything worked with a different set of tables. Did not follow through investigating that, though.

huangapple
  • 本文由 发表于 2023年3月31日 20:06:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75898355.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定