Exclusive Join 又是NULL

SetA

  a 

-----

  1

  3

  5

NULL

 

 

SetB

  a 

-----

  1

  2

  3

  4

  5

 

 

SELECT * FROM clsfd_working.setb WHERE a  NOT IN (SEL a FROM clsfd_working.seta )

return 0 row

原因是相当于SetB的每一个值都要满足 (b.a<>1 AND b.a<>3 AND b.a<>5 AND b.a<>NULL) = FALSE

所以,当用NOT IN的时候,必须要把NULL值排除。

应当这么写:SELECT * FROM clsfd_working.setb WHERE a  NOT IN (SEL a FROM clsfd_working.seta WHERE a is not NULL )

 

 

SELECT a FROM clsfd_working.setb EXCEPT SEL a FROM clsfd_working.seta

  a

-----

  2

  4

 

SELECT * FROM clsfd_working.setb b WHERE NOT EXISTS (SEL 1 FROM clsfd_working.seta a WHERE b.a = a.a )

  a

-----

  2

  4

 

SELECT b.a

FROM clsfd_working.setb b

LEFT JOIN clsfd_working.seta a
ON b.a = a.a
WHERE a.a IS NULL

  a

-----

  2

  4

 

一般在做NOT IN,IN, EXISTS, NOT EXISTS等查询的时候,特别要注意连接列是否为NULL,如果为NULL就要特别处理。

你可能感兴趣的:(JOIN,null)