SQL query through an intermediate table

Posted by Bryan on Stack Overflow See other posts from Stack Overflow or by Bryan
Published on 2010-06-12T17:10:13Z Indexed on 2010/06/12 17:12 UTC
Read the original article Hit count: 289

Filed under:
|
|
|

Given the following tables:

Recipes
| id | name
| 1  | 'chocolate cream pie'
| 2  | 'banana cream pie'
| 3  | 'chocolate banana surprise'

Ingredients
| id | name
| 1  | 'banana'
| 2  | 'cream'
| 3  | 'chocolate'

RecipeIngredients
| recipe_id | ingredient_id
|     1     |      2
|     1     |      3
|     2     |      1
|     2     |      2
|     3     |      1
|     3     |      3

How do I construct a SQL query to find recipes where ingredients.name = 'chocolate' and ingredients.name = 'cream'?

© Stack Overflow or respective owner

Related posts about sql

Related posts about query