zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

SQL基础【六、and与or】

SQL基础 and or
2023-09-14 09:04:57 时间

And和or在where子语句中把两个或多个条件结合起来。如果需要两个条件都成立就是用and如果只需要其中一个条件成立就使用or

Select * from user where user_name = 'mary' and user_age = 12

需要注意的是SQL使用单引号来环绕文本值,如果是数值则不需要引号:

Select * from user where user_name='mary' or user_age =13

 

结合and和or使用圆括号来组成复杂的表达式

Select * from user where (user_name = 'mary' and user_age = 12) or(user_age =13)

 

 

希望能对大家有所帮助。