w3resource logo


>MySQL and operator

MySQL AND operator

<<PreviousNext>>

Description

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

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


Example

Code

SELECT 5 && 5;

Explanation

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

Output

MYSQL AND

Example of MySQL AND operator with zero input

Code

SELECT 5 && 0;

Explanation

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

Output

MYSQL AND EXAMPLE

Example of MySQL AND operator with NULL input

Code

SELECT 5 && NULL;

Explanation

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

Output

MYSQL AND EXAMPLE1

Example of MySQL AND operator with zero and NULL input

Code

SELECT 0 && NULL;

Explanation

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

Output

MYSQL AND EXAMPLE2

Example of MySQL AND operator with both inputs are NULL

Code

SELECT NULL && NULL;

Explanation

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

Output

MYSQL AND EXAMPLE3

photo credit: billyrosendale Photo is used under creative Common License.

<<PreviousNext>>

Rate this tutorial


Your Rating: not set

Share this tutorial

RSS Feed