MySQL Wildcards

MySQL Wildcards

MySQL Aliases

MySQL Aliases

MySQL Data Types

MySQL Data Types

MySQL Interview Questions

MySQL Interview Questions and Answers


MySQL ALL Operator

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

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

MySQL ALL OPERATOR Syntax

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

Syntax

SELECT col1, col2,....
FROM tablename
WHERE col1 ALL (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 ALL OPERATOR example with SELECT statement

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

Example

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

Note:

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

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