Home »
MySQL
MySQL ANY Operator
MySQL | ANY Operator: Learn about the MySQL ANY Operator, with its explanation, syntax, and query examples.
Submitted by Apurva Mathur, on September 14, 2022
ANY Operator
The ANY operator is used when you have many conditions and you want the result TRUE if any of the conditions returns TRUE. It always returns a Boolean value i.e. true if any of the given conditions are successfully executed, and an empty set if none of the conditions gets any value in return.
This operator is widely used when you want to execute a sub-query inside a query.
ANY Operator Syntax
SELECT column1, column2, ...
FROM table_name
WHERE (expression) operand ANY (sub query)
Here operand can be any of the following : >, <, >=, <=, != , =, <>
Let us see some examples;
ANY Operator Examples
Suppose we have a table named "student_details" and inside this table, we have the following columns,
And table is named as attendance and inside this table, we have the following columns:
CASE 1: Using ANY operator with subquery
SELECT ID FROM student_details
WHERE ID= ANY (SELECT ID FROM attendance);
This query returns the result by comparing all the values from the subquery.
CASE 2: Using ANY and IN Operator
The following query returns the result which has commons ID's.
SELECT ID FROM student_details
WHERE ID= ANY (SELECT ID FROM attendance WHERE ID IN (2, 4, 13));