来自两个不同表的 SQLITE 查询

SQLITE Query from two different tables

我的数据库中有两个表,Recipes TableIngredients Table

数据库如下所示:

Recipes Table:
   recipe_id
   recipe_name

Ingredients Table:
   ingredient_id
   recipe_id
   ingredient_name

这些表由 recipe_id 连接。

我正在开发的功能允许用户select 最多 四种成分,并且将显示包含这些成分的所有食谱。

我要进行的查询如下:

Get all the recipes that contain ingredients pork, pepper, tomato, salt.

查询应该return仅包含所有成分的食谱。

我该怎么做?

编辑:我知道如何连接表,但无法创建提供我想要的结果的查询。在这一点上,我有点想寻找直接的答案,而不是关于如何自己做的建议。谢谢。

试试这样的东西:

SELECT recipe_id
FROM ingredients
WHERE ingredients_name IN ('pork', 'pepper', 'tomato', 'salt')
GROUP BY recipe_id
HAVING COUNT(distinct ingredients_name) = 4