空值上的 SQL 内部联接

2021-12-17 00:00:00 join sql null sql-server

我有一个加入

SELECT * FROM Y
INNER JOIN X ON ISNULL(X.QID, 0) = ISNULL(y.QID, 0) 

Isnull 像这样的 Join 使它变慢.这就像有条件加入.有没有办法解决这样的问题?我有很多记录,其中 QID 为 Null

Isnull in a Join like this makes it slow. It's like having a conditional Join. Is there any work around to something like this? I have a lot of records where QID is Null

任何人都有一个不需要修改数据的解决方法

Anyone have a work around that doesn't entail modifying the data

推荐答案

你有两个选择

INNER JOIN x
   ON x.qid = y.qid OR (x.qid IS NULL AND y.qid IS NULL)

或者更简单

INNER JOIN x
  ON x.qid IS NOT DISTINCT FROM y.qid

相关文章