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,

ANY Operator Example 1

And table is named as attendance and inside this table, we have the following columns:

ANY Operator Example 2

CASE 1: Using ANY operator with subquery

SELECT ID FROM student_details 
ANY Operator Example 3

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));
ANY Operator Example 4


Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.