-6

这个查询给了我 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    
4

1 回答 1

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 )
              )
      ) ;
于 2012-05-15T22:41:17.870 回答