2行显示为1

时间:2012-05-15 21:16:27

标签: tsql

此查询为我提供了2行,但结果只显示了1行。我不明白为什么。我希望结果为2行。

 SELECT *
 FROM table AS S1
      INNER JOIN table AS S2
        ON S1.code = S2.code
 WHERE  S1.column1 IS NULL
   AND S2.column1 IS NOT NULL

这是我期待的输出:

预期输出:

ID    login    email         code    column1
--------------------------------------------
96    testid1  test-Email1   XPQR    NULL
97    testid1  test-Email1   XPQR    P    

1 个答案:

答案 0 :(得分:2)

只是猜测:

SELECT *
FROM table AS S1
WHERE EXISTS 
      ( SELECT *
        FROM table AS S2
        WHERE ( S2.code = S1.code )
          AND (  ( S1.column1 IS NULL  AND  S2.column1 IS NOT NULL ) 
              OR ( S2.column1 IS NULL  AND  S1.column1 IS NOT NULL )
              )
      ) ;