> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oxla.com/llms.txt
> Use this file to discover all available pages before exploring further.

# BOOL_AND

## Overview

The `BOOL_AND()` function calculates all the boolean values in the aggregated group, which will have these results:

* `true` if all the values are `true` for every row.
* `false` if at least one row in the group is `false`.

The input and the return type must be in `BOOL`.

<Info>`NULL` values are not aggregated, so it will return `NULL` if there are zero input rows.</Info>

## Examples

In this example, we will use a payment table that stores details of the orders, whether the order has been paid or unpaid by the customer:

```sql theme={null}
CREATE TABLE payment (
    orderid int,
    custname text,
    orderproduct text,
    ordertotal real,
    paid boolean
);
INSERT INTO payment (orderid, custname, orderproduct, ordertotal, paid)
VALUES 
(9557411, 'Maya', 'Jeans', 10.5, true),
(9557421, 'Aaron', 'T-Shirt', 9.2, true),
(9557451, 'Alex', 'Hat', 10.8, true),
(9557311, 'Will', 'Hat', 8.5, true),
(9557321, 'Will', 'T-Shirt', 12.15, true),
(9557351, 'Maya', 'T-Shirt', 9.5, true),
(9557221, 'Maya', 'Jeans', 11.02, true),
(9557251, 'Alex', 'Jeans', 11.09, true),
(9557231, 'Aaron', 'Hat', 14.56, false),
(9557281, 'Aaron', 'Hat', 12.15, true),
(9557291, 'Will', 'T-Shirt', 13.1, true);
```

```sql theme={null}
SELECT * FROM payment;
```

The above query will show the following table:

```sql theme={null}
+----------+-----------+---------------+-------------+-------+
| orderid  | custname  | orderproduct  | ordertotal  | paid  |
+----------+-----------+---------------+-------------+-------+
| 9557411  | Maya      | Jeans         | 10.5        | t     |
| 9557421  | Aaron     | T-Shirt       | 9.2         | t     |
| 9557451  | Alex      | Hat           | 10.8        | t     |
| 9557311  | Will      | Hat           | 8.5         | t     |
| 9557321  | Will      | T-Shirt       | 12.15       | t     |
| 9557351  | Maya      | T-Shirt       | 9.5         | t     |
| 9557221  | Maya      | Jeans         | 11.02       | t     |
| 9557251  | Alex      | Jeans         | 11.09       | t     |
| 9557231  | Aaron     | Hat           | 14.56       | f     |
| 9557281  | Aaron     | Hat           | 12.15       | t     |
| 9557291  | Will      | T-Shirt       | 13.1        | t     |
+----------+-----------+---------------+-------------+-------+
```

### Case #1: `BOOL_AND` with a false result

We will find out if all customers have paid for their orders using the query below:

```sql theme={null}
SELECT BOOL_AND(paid) AS "final_result" FROM payment;
```

In the `BOOL_AND` function, if there is at least one `FALSE` value, the overall result will be `FALSE`. The final output shows that there is an order that hasn’t been paid.

```sql theme={null}
+--------------+
| final_result |
+--------------+
| f            |
+--------------+
```

### Case #2: `BOOL_AND` with a true result

We will find out if Maya has paid for her orders using the query below:

```sql theme={null}
SELECT BOOL_AND(paid) AS Maya_Paid
FROM payment
WHERE custname ='Maya';
```

In the `BOOL_AND` function, if all values are `TRUE`, then the overall result will be `TRUE`. The final output shows that Maya has paid all her orders.

```sql theme={null}
+------------+
| maya_paid  |
+------------+
| t          |
+------------+
```
