[code=Delphi(Pascal)]select * from tb where id in (1,5) --结果是:id 等于1或5的数据 select * from tb where id not in (1,5) --结果是:id 不等于1或5的数据 select * from tb where exists (select 1 from tb a where id=tb.id+1) --结果是:存在比id大1的数据 select * from tb where not exists (select 1 from tb a where id=tb.id+1) --结果是:不存在比id大1的数据[/code]
还有 any 和 all 解释一下
直接看t-sql语法说明不就得了?
SELECT * FROM 表 WHERE 字段=any(SELECT 字段 FROM 表) SELECT * FROM 表 WHERE 字段=all(SELECT 字段 FROM 表)--any只要有一个符合条件即可而all必须所有条件全符合,结合=、<>等比较符号使用
--结果是:id 等于1或5的数据
select * from tb where id not in (1,5)
--结果是:id 不等于1或5的数据
select * from tb where exists (select 1 from tb a where id=tb.id+1)
--结果是:存在比id大1的数据
select * from tb where not exists (select 1 from tb a where id=tb.id+1)
--结果是:不存在比id大1的数据[/code]
SELECT * FROM 表 WHERE 字段=all(SELECT 字段 FROM 表)--any只要有一个符合条件即可而all必须所有条件全符合,结合=、<>等比较符号使用