Site icon TestingDocs.com

MySQL ANY Operator

Overview

In this tutorial, we will learn about MySQL ANY operator with example. The quantifier keywords ALL, ANY, and SOME allow comparison with multiple rows.

We can use the ANY comparison operator in a comparison with a column subquery results to get any rows where the comparison is true by the subquery. Comparisons using the keyword ANY will succeed for any values in the column of data found by the subquery which succeed in the comparison.

Example

In this example, we will use the Country and the CountryLanguage tables from the world MySQL database.

ANY Operator

We will use the ANY operator to find  the countries from the Europe continent, and, for each country tests whether the country is among the worldwide list of countries where ‘German’ is spoken.

mysql> SELECT Name
-> FROM Country
-> WHERE Continent = ‘Europe’
-> AND Code = ANY (SELECT CountryCode
-> FROM CountryLanguage
-> WHERE Language = ‘German’);

+—————-+
| Name |
+—————-+
| Austria |
| Belgium |
| Switzerland |
| Czech Republic |
| Germany |
| Denmark |
| Hungary |
| Italy |
| Liechtenstein |
| Luxembourg |
| Poland |
| Romania |
+—————-+
12 rows in set (0.00 sec)

The IN operator when used with a subquery is equivalent to = ANY operator.

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Exit mobile version