# Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

## MySQL AND operator

AND operator

MySQL logical AND operator compares two expressions and returns true if both of the expressions are true.

Syntax :

AND, &&

This operator returns 1 if all operands are nonzero and not NULL, 0 if one or more operands are 0, otherwise, NULL is returned.

MySQL Version : 5.6

Example : MySQL AND operator

In the following MySQL statement all the operands are non-zero (5 and 5) and both of them are not NULL, so logical and operator returns 1.

1. SELECT 5 && 5;

Output :

MySQL> SELECT 5 && 5;

+--------+

| 5 && 5 |

+--------+

|      1 |

+--------+

1 row in set (0.00 sec)

Example of MySQL AND operator with zero input

In the following MySQL statement, one of the operands is non zero (5 and 0), so logical and operator returns 0.

1. SELECT 5 && 0;

Output :

MySQL> SELECT 5 && 0;

+--------+

| 5 && 0 |

+--------+

|      0 |

+--------+

1 row in set (0.00 sec)

Example of MySQL AND operator with NULL input

In the following MySQL statement, one of the operands is non zero (5) and another one is NULL, so logical and operator returns NULL.

1. SELECT 5 && NULL;

Output :

MySQL> SELECT 5 && NULL;

+-----------+

| 5 && NULL |

+-----------+

|      NULL |

+-----------+

1 row in set (0.00 sec)

Example of MySQL AND operator with zero and NULL input

In the following MySQL statement, one of the operands is zero (0) and another one is NULL, so logical and operator returns 0.

1. SELECT 0 && NULL;

Output :

MySQL> SELECT 0 && NULL;

+-----------+

| 0 && NULL |

+-----------+

|         0 |

+-----------+

1 row in set (0.00 sec)

Example of MySQL AND operator with both inputs are NULL

In the following MySQL statement, all the operands are NULL. So the operator returns NULL.

1. SELECT NULL && NULL;

Output :

MySQL> SELECT NULL && NULL;

+--------------+

| NULL && NULL |

+--------------+

|         NULL |

+--------------+

1 row in set (0.00 sec)