Tutorial Gateway

  • C Language
  • Java
  • R
  • SQL
  • MySQL
  • Python
  • BI Tools
    • Informatica
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • QlikView
  • Js

MySQL BIT_OR Function

by suresh

MySQL BIT_OR is one of the Aggregate Function, which performs Bit wise OR operation on all bits. First, this function will convert all decimal values into binary values, and perform bit wise OR operation on those binary values. In this article we will show you, How to use this BIT_OR in MySQL with example.

MySQL BIT_OR Syntax

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

SELECT BIT_OR (Expression)
FROM [Source]

The Truth Table behind this function is

xyx BIT_OR y
000
011
101
111

MySQL BIT_OR Function Example 1

In this example, we are going to implement the BIT_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 shown below

MySQL BIT_OR Function Example 1

The below statement will find the Bit wise OR values of Sales 1 and Sales 2 columns.

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

OUTPUT

MySQL BIT_OR Function Example 2

x = 9 = 1001

y = 12 = 1100

and the Bit wise OR for the above bits is 1101 = 8 + 4 + 0 + 1 = 13

MySQL BIT_OR – Group By Example

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

MySQL BIT_OR Example 1

CODE

-- MySQL Aggregate BIT_OR Function Example
USE company;
SELECT Profession,
       BIT_OR(Yearly_Income)
FROM dupcustomerdetails
GROUP BY Profession;

OUTPUT

MySQL BIT_OR Function Example 3

Thank You for Visiting Our Blog

Placed Under: MySQL

Stay in Touch!

Sign Up to receive Email updates on Latest Tutorials

  • C Programs
  • Java Programs
  • SQL FAQ’s
  • Python Programs
  • SSIS
  • Tableau
  • JavaScript

Copyright © 2019 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy