Problem & expected result
=========================

Suppose I have the following table `t`:

```
id          f_id        col1
----------  ----------  ----------
1           1           B
2           1           C
3           2           A
4           2           C
5           2           D
6           2           E
7           3           A
8           3           D
9           3           E
10          4           A
11          4           B
12          5           C
13          5           D

```

I would like to select all distinct `f_id` such that `col1` contains one of the following combinations of values:

* A and C
* A and D
* A and C and D

The expected result would therefore be:

```
f_id
----------
2
3

```

Own attempt
===========

Based on a [previous question](https://stackoverflow.com/questions/68090817/group-by-where-items-in-associated-table-exist-in-sqlite3/68091139#68091139) I tried the following query

```
SELECT f_id
FROM t
WHERE (col1 IN ('A', 'C')) or (col1 in ('A', 'D'))
GROUP BY f_id
HAVING COUNT(distinct col1) >= 2;

```

This query however also matches with groups which contain C and D, but not A. I do not want this because A is important. The above query results in the following:

```
f_id
----------
2
3
5

```

How do I obtain the desired result?

Original script
===============

For convenience, here is the code to generate the original table:

```
drop table if exists t;
CREATE TABLE t (id INTEGER, f_id INTEGER, col1 VARCHAR(1));
INSERT INTO t (id, f_id, col1) VALUES
  (1, 1, 'B'),
  (2, 1, 'C'),
  (3, 2, 'A'),
  (4, 2, 'C'),
  (5, 2, 'D'),
  (6, 2, 'E'),
  (7, 3, 'A'),
  (8, 3, 'D'),
  (9, 3, 'E'),
  (10, 4, 'A'),
  (11, 4, 'B'),
  (12, 5, 'C'),
  (13, 5, 'D')
;

```