
- 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
How to work multiple AND conditions in MySQL?
To work with multiple AND conditions in MySQL, following is the syntax −
select *from yourTableName where yourColumnName1=yourValue1 and yourColumnName2=yourValue2 and yourColumnName3=yourValue3;
Let us first create a table −
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentAge int, StudentCountryName varchar(40) ); Query OK, 0 rows affected (0.59 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(StudentName,StudentAge,StudentCountryName) values('John',23,'US'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentName,StudentAge,StudentCountryName) values('Carol',21,'UK'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(StudentName,StudentAge,StudentCountryName) values('John',21,'US'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentName,StudentAge,StudentCountryName) values('John',21,'AUS'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+-----------+-------------+------------+--------------------+ | StudentId | StudentName | StudentAge | StudentCountryName | +-----------+-------------+------------+--------------------+ | 1 | John | 23 | US | | 2 | Carol | 21 | UK | | 3 | John | 21 | US | | 4 | John | 21 | AUS | +-----------+-------------+------------+--------------------+ 4 rows in set (0.00 sec)
Following is the query for multiple AND conditions in MySQL −
mysql> select *from DemoTable where StudentName="John" and StudentAge=21 and StudentCountryName="AUS";
Output
+-----------+-------------+------------+--------------------+ | StudentId | StudentName | StudentAge | StudentCountryName | +-----------+-------------+------------+--------------------+ | 4 | John | 21 | AUS | +-----------+-------------+------------+--------------------+ 1 row in set (0.00 sec)
- Related Articles
- How to create conditions in a MySQL table with multiple columns?
- Multiple COUNT() for multiple conditions in a single MySQL query?
- MySQL If statement with multiple conditions?
- How to apply multiple AND conditions to a data frame in R?
- How to update array with multiple conditions in MongoDB
- How to calculate the median with multiple conditions in Excel?
- How to order and select query with conditions in MySQL?
- Implement multiple conditions in MongoDB?
- How to use multiple conditions in one if statement in Python?
- How to create a replacement column with multiple conditions and NA in R data frame?
- How to create a replacement column with multiple conditions and NA in data.table object in R?
- How to correctly implement conditions in MySQL stored procedure?
- Is there an operator in MySQL to implement multiple NOT conditions like WHERE id != 5 AND id != 10 AND id != 15?
- Set multiple conditions in MongoDB and fetch value in a range
- MongoDB query to $pull / $unset with multiple conditions?

Advertisements