Subject | RE: [firebird-support] Differents results using EXISTS |
---|---|
Author | Leyne, Sean |
Post date | 2008-03-25T15:33:14Z |
Eduardo,
The correct NOT EXISTS SQL would be:
SELECT
COUNT(distinct(C.codpostal))
FROM CUBOLABO C
WHERE
C.CODPOSTAL <> 0
AND NOT EXISTS(
SELECT 1
FROM DETCP D
WHERE
(D.intcabzonas = 2)
AND (D.codpostal = C.codpostal)
)
Sean
> The following query:...
>
> SELECT COUNT(distinct(codpostal))
> FROM CUBOLABO WHERE CODPOSTAL <> 0
> AND codpostal not in ( SELECT distinct(codpostal) FROM DETCP WHERE
> intcabzonas = 2)
> Returns 1360 (the correct value)intcabzonas =
>
>
> If I change to:
>
> SELECT COUNT(distinct(codpostal))
> FROM CUBOLABO WHERE CODPOSTAL <> 0
> AND NOT EXISTS( SELECT distinct(codpostal) FROM DETCP WHERE
> 2)...
>
>The 2 SQL are not equivalent!
> But returns 0.
The correct NOT EXISTS SQL would be:
SELECT
COUNT(distinct(C.codpostal))
FROM CUBOLABO C
WHERE
C.CODPOSTAL <> 0
AND NOT EXISTS(
SELECT 1
FROM DETCP D
WHERE
(D.intcabzonas = 2)
AND (D.codpostal = C.codpostal)
)
Sean