MySQL BIT_OR Function

MySQL BIT_OR is one of the Aggregate Functions which performs Bitwise OR operation on all bits. First, this BIT_OR function converts all decimal values into binary values and performs a bitwise OR operation on those binary values.


The basic syntax of the BIT_OR Function is as shown below:

SELECT BIT_OR (Expression)
FROM [Source]

The Truth Table behind this BIT_OR function is

xyx BIT_OR y

MySQL BIT_OR Function Example

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

Aggregate Functions Source Table 1

The below MySQL statement finds the Bitwise OR values of Sales 1 and Sales 2 columns.

USE company;
FROM dupemploy2;
bitwise OR Example 2

x = 9 = 1001

y = 12 = 1100 and the Bitwise OR for the above bits is 1101 = 8 + 4 + 0 + 1 = 13

MySQL BIT OR Group By Example

In this Aggregate Function example, we are going to use the BIT_OR function along with the Group By clause. For this MySQL Bitwise OR group by example, we are going to use the below shown data

Customer table 1


USE company;
SELECT Profession,
FROM dupcustomerdetails
GROUP BY Profession;
MySQL BIT_OR Function Example 3

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.