- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
While fetching the data as output, how can I use multiple conditions on same column?
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)
Advertisements