Reprence Html CSS javascript PHP MySQL Bootsrap

The MySQL ANY and ALL Operators

The ANY and ALL operators allow you to perform a comparison between a single column value and a range of other values.

The ANY Operator

120

ANY Syntax

121

122

The ALL Operator

123

ALL Syntax With SELECT

124

ALL Syntax With WHERE or HAVING

125

126

Demo Database

Below is a selection from the "Products" table in the Northwind sample database:

127

And a selection from the "OrderDetails" table:

128

SQL ANY Examples

The following SQL statement lists the ProductName if it finds ANY records in the OrderDetails table has Quantity equal to 10 (this will return TRUE because the Quantity column has some values of 10):


The following SQL statement lists the ProductName if it finds ANY records in the OrderDetails table has Quantity larger than 99 (this will return TRUE because the Quantity column has some values larger than 99):


The following SQL statement lists the ProductName if it finds ANY records in the OrderDetails table has Quantity larger than 1000 (this will return FALSE because the Quantity column has no values larger than 1000):



SQL ALL Examples

The following SQL statement lists ALL the product names:


The following SQL statement lists the ProductName if ALL the records in the OrderDetails table has Quantity equal to 10. This will of course return FALSE because the Quantity column has many different values (not only the value of 10):