MySQL Wildcards

MySQL Wildcards

MySQL Aliases

MySQL Aliases

MySQL Data Types

MySQL Data Types

MySQL Interview Questions

MySQL Interview Questions and Answers


MySQL ANY Operator

The MySQL ANY operators allow you to perform a comparison operation, return TRUE if the comparison is TRUE for ANY of the values in the column that the subquery returns.

Note: The operator must be a standard comparison operator (=, <>, !=, >, >=, <, or <=).

MySQL ANY OPERATOR Syntax

To perform a comparison operation, return TRUE if any of the subquery values meet the condition, use the following syntax:

Syntax

SELECT col1, col2,....
FROM tablename
WHERE col1 ANY (SELECT col1 FROM tablename WHERE condition);

Parameters:

tablename: The table name from which you want to perform ANY operator.

subquery: Usually a SELECT statement starts with SELECT * or column name. MySQL ignores the SELECT list from subquery.

MySQL ANY OPERATOR example with SELECT statement

The following MySQL, returns TRUE and lists the "accountName" if it finds ANY records in the "tblbankheadquartersandaddress" table:

Example

SELECT A.accountName FROM tblbankdemataccountcharges A 
WHERE A.bankId = ANY (SELECT B.pk FROM tblbankheadquartersandaddress B) LIMIT 5;

Note:

In the above example, the ANY operator will return all records from the "tblbankdemataccountcharges" table if it finds ANY records in the "tblbankheadquartersandaddress" table.

You can use MySQL Command Line Client to use ANY operator in subquery to perform comparison operation. It will look like this: