Reputation: 1120
I have two queries:
1)
SELECT a.n
FROM account a, contract c
WHERE c.n = a.r$contract
AND c.n IN (
SELECT account.n
FROM account, contract
WHERE contract.n = account.r$contract
AND account.n = contract.n )
ORDER BY a.n
and
2)
SELECT account.n
FROM account, contract
WHERE contract.n = account.r$contract
AND account.n = contract.n
In 1 there are 47 rows, but in 2 - 15. I can't understand why
Upvotes: 0
Views: 45
Reputation: 2960
Not sure, I'll just try...
If query 2 returns 15 rows, then also the inner select of query 1 does, as it looks identical to me..
so query 1 is like
SELECT a.n
FROM account a, contract c
WHERE c.n = a.r$contract
AND c.n IN ( <any of the 15 values> )
ORDER BY a.n
And that is different from
SELECT a.n
FROM account a, contract c
WHERE c.n = a.r$contract
AND c.n = a.n ( <-just one possible value)
ORDER BY a.n
So that might explain why you get different result sets.
Upvotes: 1