> For the complete documentation index, see [llms.txt](https://gyansetu-sql.gitbook.io/sql-programming/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-sql.gitbook.io/sql-programming/sql-select/sql-any-and-all-operators.md).

# SQL ANY and ALL Operators

### The SQL ANY and ALL Operators

The ANY and ALL operators are used with a WHERE or HAVING clause.

The ANY operator returns true if any of the subquery values meet the condition.

The ALL operator returns true if all of the subquery values meet the condition.

#### ANY Syntax

```sql
SELECT column_name(s)
FROM table_name
WHERE column_name operator ANY
(SELECT column_name FROM table_name WHERE condition);
```

#### ALL Syntax

```sql
SELECT column_name(s)
FROM table_name
WHERE column_name operator ALL
(SELECT column_name FROM table_name WHERE condition);
```

> **Note:** The *operator* must be a standard comparison operator (=, <>, !=, >, >=, <, or <=).<br>

### Demo Database

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

![](https://826093633-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LS8lPNzCGPR5-DLbGXv%2F-LSc854yX-Wxh9G9nbaY%2F-LSc8k_vonrfKE5TZEti%2Fimage.png?alt=media\&token=db60cc03-270f-42a8-82bf-4304ef25fa65)

And a selection from the "OrderDetails" table:

![](https://826093633-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LS8lPNzCGPR5-DLbGXv%2F-LSc854yX-Wxh9G9nbaY%2F-LSc8phK6PGHjPxI1uBW%2Fimage.png?alt=media\&token=c0e7cf90-2145-41dd-b1ac-519d8717064b)

\
SQL ANY Examples

The ANY operator returns TRUE if any of the subquery values meet the condition.

The following SQL statement returns TRUE and lists the product names if it finds ANY records in the OrderDetails table that quantity = 10:

```sql
SELECT ProductName
FROM Products
WHERE ProductID = ANY (SELECT ProductID 
FROM OrderDetails WHERE Quantity = 10);
```

The following SQL statement returns TRUE and lists the productnames if it finds ANY records in the OrderDetails table that quantity > 99:

```
SELECT ProductName
FROM Products
WHERE ProductID = ANY 
```

SQL ALL Example

The ALL operator returns TRUE if all of the subquery values meet the condition.

The following SQL statement returns TRUE and lists the productnames if ALL the records in the OrderDetails table has quantity = 10:

```sql
SELECT ProductName
FROM Products
WHERE ProductID = ALL 
(SELECT ProductID FROM OrderDetails WHERE Quantity = 10);
```

\
\ <br>
