What are the operators in MYSQL and How to use operators in MYSQL with example?
In MYSQL Operators are used to put a condition in a MySQL query. Below is the list of most common and useful operators in MYSQL
Operators in MYSQL
- AND
- OR
- Like
- In
MySql Operators are used for testing more than two conditions in a query. Let’s see all the above-listed MySQL operators with examples.
AND Operator in MYSQL
The AND operator is used to combines two or more Boolean expressions and returns true only if both expressions are true. The AND operator returns false if one of the two expressions are to false.
Syntax
WHERE Condition1 AND condition2 ……. AND Condition_n;
Example:
SELECT expression1, expression2, ….expression_n, Aggregate_function (expression) FROM tables [WHERE conditions] AND ;
OR Operator in MYSQL
When two or more condition is there, then at least one condition should be satisfied.
Syntax:
WHERE Condition1 OR condition2 ……. OR Condition_n;
Example:
SELECT expression1, expression2, ….expression_n, Aggregate_function (expression) FROM tables [WHERE conditions] OR ;
How to use multiple operators in a MySQL query
AND and OR condition can be used together with select, insert, update or delete statements.
Syntax:
WHERE Condition1 AND condition2 ……. OR Condition_n;
Example:
SELECT expression1, expression2, ….expression_n, Aggregate_function (expression) FROM tables [WHERE conditions] AND expression1, Expression2, ..expression_n OR condition;
Like Operator in MYSQL
It is used to match the pattern with the set of requirements.
Syntax:
Expression LIKE pattern [ESCAPE ‘escape_character’]
Example:
SELECT expression1, expression2, ….expression_n, Aggregate_function (expression) FROM tables WHERE conditions LIKE
IN Operator in MYSQL
It is used in the statement when you want to remove, more number of Or from the command.
Syntax:
Expression IN (value1, value2, ….value_n);
Example:
SELECT expression1, expression2, ….expression_n, Aggregate_function (expression) FROM tables WHERE conditions LIKE