在我的 rdbms 上,这些表达式给出完全相同的输出:
select avd from avdelning where avd not in(select avd from försäljning) order by avd
select avd from avdelning except (select avd from försäljning) order by avd
似乎你可以用 SQL 写的东西你可以用 SQLEXCEPT
写NOT IN
,同样地 for UNION
andOR
和AND
and INTERSECT
。你能告诉我这些关键字之间的区别吗?例如,与其他构造select * from person where person not in (select * from person where name='foo')
相同select * from person except where name='foo'
且相似。它们真的是等价的吗?
SELECT PersonId FROM person EXCEPT (SELECT PersonId FROM Addresses WHERE streetname='Elm Street')
=
SELECT PersonId FROM person WHERE PersonId NOT IN(SELECT PersonID FROM Addresses WHERE StreetName = 'Elm Street')
?