ELEVATE YOUR BUSINESS WITH

Limitless customization options & Elementor compatibility let anyone create a beautiful website with Valiance.

Operators in MySql

SELECT * FROM `itio_tutorial_master` WHERE `tutorial_menu`='7' AND `tutorial_submenu`='64' AND `tutorial_status`=1 LIMIT 1

Operators in MySql

MySQL Operators

MySQL provides several operators to perform operations in queries. Operators are classified into different categories:


1. Arithmetic Operators

Used for mathematical calculations.

OperatorDescriptionExampleResult
+Addition5 + 38
-Subtraction10 - 46
*Multiplication7 * 214
/Division10 / 25
%Modulus (Remainder)10 % 31

Example Query:

SELECT 10 + 5 AS sum, 10 / 2 AS division;


2. Comparison Operators

Used to compare values and return TRUE (1), FALSE (0), or NULL.

OperatorDescriptionExampleResult
=Equal toprice = 100Rows where price is 100
!= or <>Not equal toprice != 50Rows where price is NOT 50
>Greater thanprice > 200Prices greater than 200
<Less thanprice < 150Prices less than 150
>=Greater than or equal toprice >= 100Prices 100 or more
<=Less than or equal toprice <= 300Prices 300 or less
BETWEENRangeprice BETWEEN 100 AND 500Prices between 100 and 500
INMatches any value in a listcity IN ('New York', 'LA')Matches New York or LA
LIKEPattern matchingname LIKE 'A%'Names starting with A
IS NULLChecks for NULL valuessalary IS NULLFinds NULL salaries

Example Query:

SELECT * FROM products WHERE price BETWEEN 100 AND 500;


3. Logical Operators

Used to combine multiple conditions in WHERE clauses.

OperatorDescriptionExample
ANDReturns TRUE if both conditions are TRUEprice > 100 AND stock > 10
ORReturns TRUE if at least one condition is TRUEprice > 500 OR stock < 5
NOTReverses the conditionNOT (price > 1000)

Example Query:

SELECT * FROM customers WHERE city = 'New York' AND age > 30;


4. Bitwise Operators

Used to perform operations at the binary level.

OperatorDescriptionExampleBinary Result
&AND5 & 31 (101 & 011 = 001)
``OR`5
^XOR5 ^ 36 (101 ^ 011 = 110)
<<Left Shift5 << 110 (101 << 1 = 1010)
>>Right Shift5 >> 12 (101 >> 1 = 10)

Example Query:

SELECT 5 & 3 AS result; -- Output: 1


5. Assignment Operators

Used to assign values in queries.

OperatorDescriptionExample
=Assign valueSET price = 200
:=Assign value in expressionsSELECT @var := 10;

Example Query:

SET @x = 100;SELECT @x; -- Output: 100


6. Other Special Operators

OperatorDescriptionExample
EXISTSChecks if a subquery returns resultsEXISTS (SELECT * FROM orders WHERE customer_id = 5)
ANYCompares a value with any in a subqueryprice > ANY (SELECT price FROM products)
ALLCompares a value with all in a subqueryprice > ALL (SELECT price FROM products)

Example Query:

SELECT * FROM customers WHERE EXISTS (SELECT * FROM orders WHERE orders.customer_id = customers.id);


Key Takeaways

Arithmetic Operators perform math operations.
Comparison Operators compare values (=, <>, >, <, BETWEEN).
Logical Operators (AND, OR, NOT) combine conditions.
Bitwise Operators work on binary data.
Assignment Operators store values in variables.
Special Operators (EXISTS, IN, LIKE) handle advanced queries.

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql