mysql join和where_mysql – 使用Join和Where

我有以下表格.

Table Name: Recipe

id topic description difficultylevel totaltime

1 Cheese Cheese Easy 10

2 Cheese1 Cheese1 Medium 50

Table Name: Ingredients

id recipeid ingredient

1 1 Butter

2 1 Cheese

3 1 Bread

现在,当我运行以下查询时,它返回配方id =“1”,即使它不应该,因为我不想要一个含有黄油的配方.

SELECT recipe.id

FROM

`recipe`

INNER JOIN ingredients ON recipe.id = ingredients.recipeid

WHERE

(recipe.description LIKE '%CHEESE%' OR recipe.topic LIKE '%CHEESE%')

AND (recipe.difficultylevel='Easy')

AND (recipe.totaltime <= 30)

AND (ingredients.ingredient <> 'Butter')

由于奶酪和面包,它会两次返回recipe.id =“1”.我需要修复查询,以便它排除recipe.id =“1”,如果它有黄油(例如)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值