In MySQL, operators are symbols used to perform operations on data in SQL queries. Here are some common types of operators:
1. Arithmetic Operators: Used for mathematical operations.
SELECT 10 + 5, 10 - 5, 10 * 5, 10 / 5, 10 % 3;
2. Comparison Operators: Used to compare values.
SELECT * FROM table_name WHERE column1 > 10 AND column2 <> 'value'
;
3. Logical Operators: Used to combine conditions.
SELECT * FROM table_name WHERE column1 > 10 AND column2 = 'value';
4. Concatenation Operator: Used to concatenate strings.
CONCAT(): Concatenates two or more strings.
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM employees;
5. NULL-Safe Equal Operator: Used to compare values, handling NULL values properly.
<=>: Returns true if both operands are equal, or both are NULL.
SELECT * FROM table_name WHERE column1 <=> NULL;
6. Assignment Operator: Used to assign a value to a variable.
:=
SET @variable_name := 10;
These are some of the most commonly used operators in MySQL queries, but there are others as well, depending on the specific requirements of your query.