LOGICAL, ARITHMETIC, COMPARISON, AND BIT OPERATORS – MYSQL

0
Advertisement

Operators are the building blocks of complex queries meaning these operators are used in the SELECT statement. There are 4 types of operators. They are the ‘Logical operators’, ‘Arithmetic operators’, ‘Comparison operators’ and the ‘Bit operators’. I will discuss these operators one by one.

 

LOGICAL OPERATORS

      Logical operators allow you to relate numbers of condition in various ways. The outcome would be reduce to either true(1) or false(0). The logical operators are the AND(&&), OR(||), and the NOT(!). The AND(&&) operator results to true only if both conditions are true. The OR(||) operator results to true if one of the conditions is true. And the NOT(!) operator results to the opposite value of the condition.

 

ARITHMETIC OPERATORS

     Arithmetic operators are used to perform basic mathematical operations while using the SELECT statement. There are 5 different type of arithmetic operators. They are the (+) sign, (-) sign, (*) sign, (/) sign and the (%) sign. The (+) sign is used to get the sum of the values you want to add. The (-) sign is used to get the difference of the values you want to subtract. The (*) sign is use to get the product and the (/) sign is used to get the quotient. The (%) sign is used to get the remainder of the values you want to divide.


COMPARISON OPERATORS

     Comparison operators are used when making comparison between values. There are many comparison operators available in mysql. There is the (=) sign that checks if both values being compared are equal. The (!=) and (<>) signs checks if both values being compared are not equal. The (>) sign checks if the first value is greater than the second value while the (<) sign checks if the first value is less than the second value. There is also the (>=) sign and the (<=) sign which checks respectively if first value if greater than of equal to or less than or equal to the second value. The (<=>) sign checks if both values are equal including their null values. The IS NULL operation checks if the value contains a NULL value. The IS NOT NULL operation checks if the value does not contain a NULL value. The BETWEEN operation checks if the value your comparing is between the value of the other two values you compared. There is also the LIKE and NOT LIKE operation which checks the first value matches or do no matches the SQL pattern of the second value.

Advertisement


BIT FUNCTIONS

     Bit functions are operators used by bits. There are seven kinds of bit functions. These are the BIT_COUNT(), (&) sign, (~) sign, (|) sign, (^) sign, (<<) sign and the (>>) sign. The BIT_COUNT() returns the number of bits that are set. The (&) sign is the bitwise AND. The (~) sign inverts the bits. The (|) sign is the bitwise OR. The (^) sign is the bitwise XOR. The (<<) sign is the left shif while the (>>) sign is the right shift.

 

For more information on how to use operators you can visit the site here.


#LOGICAL #ARITHMETIC #COMPARISON #BIT #OPERATORS #MYSQL

Advertisement

LEAVE A REPLY

Please enter your comment!
Please enter your name here