0

我有这张桌子:

Recipe = (idR, recipeTitle, prepText, cuisineType, mealType)
Ingredient = (idI, ingrDesc)
RecipIngr = (idR*, idI*)

我正在尝试显示包含蜂蜜或芥末成分的 idR 和食谱标题。这是我的查询

select idr, recipetitle
from recipe
where idr IN (select idr from recpingr where idi =
(select distinct idr from ingredient where ingrdesc like '%honey%'))
INTERSECT
select idr, recipetitle
from recipe
where idr IN (select idr from recpingr where idi =
(select distinct idr from ingredient where ingrdesc like '%mustard%'))
ORDER BY idr;

由于某种原因,这不会显示正确的数据,我不知道我做错了什么。有什么帮助吗?我的查询有问题吗?

4

3 回答 3

2

像这样的帮助?

SELECT r.idr, r.recipetitle
FROM recipe r
INNER JOIN recipingr ring
    ON ring.idr = r.idr
INNER JOIN ingredient ing
    ON ing.idi = ring.idi
WHERE ing.ingrdesc LIKE '%honey%'
OR ingrdesc LIKE '%mustard%'
ORDER BY r.idr
于 2013-04-13T16:43:49.573 回答
2

我认为你过度设计了它。为什么不这样:

select idr, recipetitle
from recipe r join recipInbg ri on r.idr = ir.idr
join ingredient i on ri.idI = i.idI
where ingrdesc like '%honey%'
or ingrdesc like '%mustard%'
于 2013-04-13T16:44:14.567 回答
1

干得好:

select r.idr, r.recipeTitle from recipe r, ingredient i, recipIngr ri
    where r.idR=ri.idR and ri.idI=i.idI and 
    (i.ingrDesc like '%honey%' or i.ingrDesc like '%mustard%')
于 2013-04-13T16:45:35.963 回答