Tutorial Gateway

  • C
  • C#
  • Python
  • SQL
  • Java
  • JS
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs
  • MySQL

MySQL BIT_AND Function

MySQL BIT_AND is one of the Aggregate Functions, which performs Bitwise AND operation on all bits. This MySQL BIT_AND function first converts all decimal values into binary values, and perform bitwise and operation on those binary values.

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 Bit_And function is

xyx BIT_AND y
000
010
100
111

MySQL BIT_AND Function Example 1

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

MySQL BIT_AND Function Example 1

The following MySQL statement finds the Bitwise 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;
MySQL BIT_AND Function Example 2

x = 9 = 1001

y = 12 = 1100

and the Bitwise 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 Aggregate Function example, We are going to use the below shown data

MySQL AVG Example 1

CODE

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

Let me take the Example for Developer Group

85000 = 10100110000001000
80000 = 10011100010000000
55000 = 01101011011011000

and the MySQL output is 0

Filed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions

Copyright © 2021ยท All Rights Reserved by Suresh.
About | Contact | Privacy Policy