将 NOT IN 替换为 JOIN
replace NOT IN with JOIN
我需要用 join 替换 NOT IN。我该怎么做,因为此查询的结果不同。
SELECT COUNT(*) as total FROM requests
WHERE
isApproved='1' AND
softDelete='0' AND
requestID NOT IN (
SELECT
DISTINCT requestID
FROM consulting
WHERE
softDelete='0' AND
isApproved='1' AND
)
SELECT COUNT(*) as total FROM requests AS R
LEFT JOIN
(
SELECT
DISTINCT requestID
FROM consulting
WHERE
softDelete='0' AND
isApproved='1' AND
) X ON R.requestID =X.requestID
WHERE R.isApproved='1' AND R.softDelete='0'
AND X.requestID IS NULL
你能试试这样吗
我需要用 join 替换 NOT IN。我该怎么做,因为此查询的结果不同。
SELECT COUNT(*) as total FROM requests
WHERE
isApproved='1' AND
softDelete='0' AND
requestID NOT IN (
SELECT
DISTINCT requestID
FROM consulting
WHERE
softDelete='0' AND
isApproved='1' AND
)
SELECT COUNT(*) as total FROM requests AS R
LEFT JOIN
(
SELECT
DISTINCT requestID
FROM consulting
WHERE
softDelete='0' AND
isApproved='1' AND
) X ON R.requestID =X.requestID
WHERE R.isApproved='1' AND R.softDelete='0'
AND X.requestID IS NULL
你能试试这样吗