

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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)
- Related Questions & Answers
- MongoDB multiple OR conditions on same key?
- How can I create a MySQL boolean column and assign value 1 while altering the same column?
- How can I use SUBSTRING_INDEX() function to get the substring as output which is between two same delimiters in a string?
- How to use multiple versions of jQuery on the same page?
- How can we get sorted output based on multiple columns?
- How to obtain the same font in Matplotlib output as in LaTex output?
- How can I use Multiple-tuple in Python?
- How can I get the output of a Matplotlib plot as an SVG?
- What happens if I will add a UNIQUE constraint on the same column for multiple times?
- How can I get the output of multiple MySQL tables from a single query?
- Set conditions while adding column values in MySQL?
- How can I filter JSON data with multiple objects?
- How can I use SPACE() function along with MySQL’s column data?
- How can I use MySQL INTERVAL keyword while extracting the part of the date?
- How can I get the output based on comparison done with column’s name using MySQL IN() function?
Advertisements