通过使用“or”逻辑运算符众所周知,mysql 的“or”运算符比较两个表达式,如果其中一个表达式为 true,则返回 true。以下示例演示了如何对同一列上的多个条件使用“or”运算符
mysql> select * from student where name = 'gaurav' or name = 'aarav';+------+--------+---------+-----------+| id | name | address | subject |+------+--------+---------+-----------+| 1 | gaurav | delhi | computers || 2 | aarav | mumbai | history |+------+--------+---------+-----------+2 rows in set (0.00 sec)
通过使用 where in(…) 子句where in(…) 子句也用于上述目的。它可以在同一列上的多个条件的查询中使用,如下所示 -
mysql> select * from student where name in ('gaurav','aarav');+------+--------+---------+-----------+| id | name | address | subject |+------+--------+---------+-----------+| 1 | gaurav | delhi | computers || 2 | aarav | mumbai | history |+------+--------+---------+-----------+2 rows in set (0.00 sec)
以上就是在获取数据作为输出时,如何在同一列上使用多个条件?的详细内容。
