MySQL Any Operator

Profile picture for user arilio666

In MySQL, ANY keyword returns the boolean value TRUE if the comparison operator is TRUE from any of the following conditions.

If any subquery condition is fulfilled when the query is executed, this keyword returns TRUE. Between ALL and ANY keywords, ALL returns TRUE when all the subqueries are satisfied.

Syntax

operand comparison operator ANY (subquery)  

Comparison Operators Which Can Be Used: =  >  <  >=  <=  <>  !=  

Example

Let us create two tables with numbers.

CREATE TABLE numbers_table1 (  
    numbers INT  
);   
INSERT INTO numbers_table1 (numbers)   
VALUES(100), (200), (257);  
  
CREATE TABLE numbers_table2 (  
    numbers int  
);   
INSERT INTO numbers_table2 (numbers)  
VALUES(800), (400), (1500);  

Here are the two tables.

any operator in mysql

mysql any operator

SELECT numbers FROM numbers_table1   
WHERE numbers > ANY (SELECT numbers FROM numbers_table2); 

mysql any operator example

  • We can see that it fetched numbers more significantly from numbers_table2, ignoring 8, which means it brought any possible way to get the more significant number.
  • Thus returned TRUE even if the condition didn't satisfy.
Tags