Select*fromStudentWHEREName='Gaurav'ORName='Aarav';+------+-------- +---------+-------"/> Select*fromStudentWHEREName='Gaurav'ORName='Aarav';+------+-------- +---------+-------">

Home >Database >Mysql Tutorial >How to use multiple conditions on the same column while getting data as output?

How to use multiple conditions on the same column while getting data as output?

WBOY
WBOYforward
2023-09-09 16:53:051592browse

How to use multiple conditions on the same column while getting data as output?

Here's how we write a query that returns only records that match multiple criteria on the same column

By using "OR" logic Operator

As we all know, MySQL's "OR" operator compares two expressions and returns TRUE if one of the expressions is TRUE. The following example demonstrates how to use the "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 the WHERE IN(…) clause

The WHERE IN(…) clause is also used for the above purposes. It can be used in queries with multiple conditions on the same column as shown below -

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)

The above is the detailed content of How to use multiple conditions on the same column while getting data as output?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete