I have one table that contains all kind of metadata about customers. It is structured like this:

```
customer_id, metadata_id, text_value

```

I want to count all customers that have a specific `text_value` for `metadata_id='metadata_1'` and for whom an entry for `metadata_id='metadata_2'` exists.

| customer\_id | metadata\_id | text\_value |
| --- | --- | --- |
| customer\_1 | metadata\_1 | yes! |
| customer\_1 | metadata\_2 | random value |
| customer\_2 | metadata\_1 | yes! |
| customer\_2 | metadata\_2 | never mind |
| customer\_3 | metadata\_1 | no! |
| customer\_3 | metadata\_2 | another value |
| customer\_4 | metadata\_1 | yes! |

I can easily get the two parts:

```
SELECT customer_id
FROM my_table
WHERE metadata_id='metadata_1' AND text_value='yes!';

SELECT customer_id
FROM my_table
WHERE metadata_id='metadata_2';

```

But how do I combine them and count them?

Here `customer_1` and `customer_2` fulfil both conditions. So the answer for the example would be 2.