Followings are the ways in which we can write a query that returns only records that matches multiple conditions on the same column
By using ‘OR’ logical operator
As we know that MySQL ‘OR’ operator compares two expressions and returns TRUE if either of the expression is TRUE. Following example demonstrate that how we can use ‘OR’ operator for multiple conditions on the same column
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)
By using WHERE IN(…) clause
WHERE IN(…) clause is also used for the above-said purpose. It can use in a query for multiple conditions on the same column as follows −
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)