MySQL ALL Operator
MySQL ALL Operator
In this tutorial, we will learn about the MySQL ALL Operator with an example. The ALL operator is a quantified comparison operator. The quantifier keywords ALL, ANY, and SOME allow comparisons with multiple rows.
To perform a comparison between a scalar value and a subquery that returns several rows of data
in a column subquery, we must use a quantified comparison.
We can use the ALL comparison operator construct in a comparison with a column subquery limits the result set to only those rows where the comparison is true for all values produced by the subquery.
Example
In this example, we will use the City table from the world MySQL database.
ALL Operator
Let’s find the names of cities which have population greater than all the cities in the United States. We can use the ALL operator against the column subquery that returns the rows of the Population column from the City table where the country code matches USA.
mysql> SELECT Name FROM City
-> WHERE Population >
-> ALL (SELECT Population FROM City
-> WHERE CountryCode =’USA’);
+——————-+
| Name |
+——————-+
| São Paulo |
| Jakarta |
| Mumbai (Bombay) |
| Shanghai |
| Seoul |
| Ciudad de México |
| Karachi |
| Istanbul |
| Moscow |
+——————-+
9 rows in set (0.01 sec)
—
MySQL Tutorials
MySQL Tutorials on this website:
https://www.testingdocs.com/mysql-tutorials-for-beginners/
For more information on MySQL Database: