以下是我们编写查询的方式,该查询仅返回与同一列上的多个条件匹配的记录
众所周知,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(…)子句也用于上述目的。它可以在查询中在同一列上使用多个条件,如下所示-
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)