MySQL supports a variety of operators that are used in SQL queries to perform different operations on data.
Operators allow us to perform data manipulation, filtering, search queries on the database.
It will add two values.
SELECT column1 + column2 AS sum FROM table;
SELECT product_code, product_price, product_tax, (product_price + product_tax) AS total_product_price FROM products;
Subtracts the right-hand operand from the left-hand operand.
SELECT column1 - column2 AS difference FROM table;
SELECT product_code, product_price, discount, (product_price - discount) AS total_product_price FROM products;
It will multiply two values.
SELECT column1 * column2 AS product FROM table;
SELECT product_code, product_price, product_unit (product_price * product_unit) AS total_product_price FROM products;
Divides the left-hand operand by the right-hand operand.
SELECT column1 / column2 AS quotient FROM table;
It will return the remainder of the division.
SELECT column1 % column2 AS remainder FROM table;
= (Equal to): Tests whether two expressions are equal.
<> or != (Not equal to): Tests whether two expressions are not equal.
< (Less than): Tests whether the value on the left is less than the value on the right.
> (Greater than): Tests whether the value on the left is greater than the value on the right.
<= (Less than or equal to): Tests whether the value on the left is less than or equal to the value on the right.
>= (Greater than or equal to): Tests whether the value on the left is greater than or equal to the value on the right.
Logical AND: Returns true if both conditions are true.
Logical OR: Returns true if at least one condition is true.
Logical NOT: Returns true if the condition is false, and false if the condition is true.
SELECT product_code, product_name, product_price, category FROM products WHERE category = 'ELECTRONICS' AND product_price > 400;
SELECT product_code, product_name, product_price, category FROM products WHERE category = 'ELECTRONICS' OR product_price > 200;
SELECT * FROM products WHERE NOT category = 'GAMES';
|| (Double pipe): Concatenates two strings.
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM users;