0

我有两个疑问:

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

2)

SELECT account.n
FROM account, contract
WHERE contract.n = account.r$contract
AND account.n = contract.n

在 1 中有 47 行,但在 2 - 15 中。我不明白为什么

4

1 回答 1

1

不确定,我试试...

如果查询 2 返回 15 行,那么查询 1 的内部选择也会返回,因为它看起来与我相同。

所以查询1就像

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

这不同于

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

所以这可以解释为什么你会得到不同的结果集。

于 2012-12-05T11:22:58.540 回答