MySQL BIT_AND is one of the Aggregate Function, which will perform Bitwise AND operation on all bits. This function will first convert all decimal values into binary values, and perform bit wise and operation on those binary values. In this article we will show you, How to use this BIT_AND in MySQL with example.

## MySQL BIT_AND Syntax

The basic syntax of the BIT_AND Function in MySQL is as shown below:

SELECT BIT_AND (Expression) FROM [Source]

The Truth Table behind this MySQL Bit_And function is

x | y | x BIT_AND y |
---|---|---|

0 | 0 | 0 |

0 | 1 | 0 |

1 | 0 | 0 |

1 | 1 | 1 |

## MySQL BIT_AND Function Example 1

In this example, we are going to implement the BIT_AND function on different columns in a table. In order to demonstrate the same, we are going to use the dup employee 2 table data that we shown below

The following statement will find the Bit wise AND values of Sales 1 and Sales 2 columns.

-- MySQL BIT_AND Function Example USE company; SELECT BIT_AND(Sales1), BIT_AND(Sales2) FROM dupemploy2;

**OUTPUT**

x = 9 = 1001

y = 12 = 1100

and the Bit wise AND for the above bits is 1000 = 8

## MySQL BIT_AND – Group By Example

In this example, we are going to use the BIT_AND function along with the Group By clause. For this, We are going to use the below shown data

**CODE**

-- MySQL Aggregate BIT_AND Function Example SELECT Profession, Yearly_Income ,bit_and(Yearly_Income) FROM company.dupcustomerdetails group by Profession;

**OUTPUT**

Let me take the Example for Developer Group

85000 = 10100110000001000

80000 = 10011100010000000

55000 = 01101011011011000

and the output will be 0

Thank You for Visiting Our Blog