'Check condition across several rows from a join

I have some entities A which can all have one or more B. How can I query "all entities A which have this and that from B"?

I can query "all entities A which have "this" or "that" from B":

SELECT *
FROM A
INNER JOIN B ON B.A_id = A.id
WHERE f = "this" OR f = "that"
GROUP BY A.ID

But I can’t check that they have "this" and "that", because I can’t check something across different rows from A.

I might use a GROUP_CONCAT, but then how can I effectively check that "blah,thing,foo,bar" has blah and foo without some unmaintainable REGEXP mess?

(I actually love regexes, but not so much in the context of an SQL query, for something that seems like it wouldn’t need a regex).

SELECT *, GROUP_CONCAT(f)
FROM A
INNER JOIN B ON B.A_ID = A.ID
WHERE f = "this" OR f = "that"
GROUP BY A.ID


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source