What is AND Operator in MySQL - MySQL Developer Tutorial

What is AND Operator in MySQL

Logical Operators are used to test some conditions. If the condition is true, the row will be selected for output.


What is AND Logical Operator : 

Logical AND operator is used when we want to return the row if all the specified conditions are true.

Scenario : 

Think about a situation where you need to return all the records from a Customer table where FName='Raza' and CountryShortName='US'

Create the Customer table with some sample records by using below scripts.


Create table Customer
 (Id int,
  FName VARCHAR(50),
  LName VARCHAR(50),
  CountryShortName CHAR(2));

insert into Customer
Values (
1,'Raza','M','PK'),
(2,'Rita','John','US'),
(3,'Sukhi','Singh',Null),
(4,'James','Smith','CA'),
(5,'Robert','Ladson','US'),
(6,'Alice','John','US'),
(7,'Raza','M','US');




To return the records where FName='Raza' and CountryShortName='US' we can use below query.


Select * From Customer
where FName='Raza'
AND CountryShortName='US';




What is AND Logical Operator in MySQL - MySQL Developer Tutorial

Noticed that our query returned single record as both conditions are only true for single record.