
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- 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 can I use SPACE() function along with MySQL’s column data?
- How can we get sorted output based on multiple columns?
- How can I use Multiple-tuple in Python?
- How to use multiple versions of jQuery on the same page?
- How can I get the output of multiple MySQL tables from a single query?
- How to create a replacement column with multiple conditions and NA in R data frame?
- How to obtain the same font in Matplotlib output as in LaTex output?
- What happens if I will add a UNIQUE constraint on the same column for multiple times?
- How can I filter JSON data with multiple objects?
- How can I get the output of a Matplotlib plot as an SVG?
- Set conditions while adding column values in MySQL?
- How can I use MySQL OCTET_LENGTH() function to count the number of characters stored in a data column?

Advertisements