当前位置: 移动技术网 > IT编程>数据库>MSSQL > SQL AND & OR 运算符

SQL AND & OR 运算符

2019年04月02日  | 移动技术网IT编程  | 我要评论

最大的猫,甜性涩爱情完整版 优酷,农村老年人保险

and 和 or 运算符用于基于一个以上的条件对记录进行过滤。

and 和 or 运算符

and 和 or 可在 where 子语句中把两个或多个条件结合起来。

如果第一个条件和第二个条件都成立,则 and 运算符显示一条记录。

如果第一个条件和第二个条件中只要有一个成立,则 or 运算符显示一条记录。

原始的表 (用在例子中的)

lastname firstname address city
adams john oxford street london
bush george fifth avenue new york
carter thomas changan street beijing
carter william xuanwumen 10 beijing

and 运算符实例

使用 and 来显示所有姓为 "carter" 并且名为 "thomas" 的人:


select * from persons where firstname='thomas' and lastname='carter'

结果:

lastname firstname address city
carter thomas changan street beijing

or 运算符实例

使用 or 来显示所有姓为 "carter" 或者名为 "thomas" 的人:


select * from persons where firstname='thomas' or lastname='carter'

结果:

lastname firstname address city
carter thomas changan street beijing
carter william xuanwumen 10 beijing

结合 and 和 or 运算符

我们也可以把 and 和 or 结合起来(使用圆括号来组成复杂的表达式):


select * from persons where (firstname='thomas' or firstname='william') and lastname='carter'

结果:

lastname firstname address city
carter thomas changan street beijing
carter william xuanwumen 10 beijing

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网