0

我迷路了,需要至少 3 个表的复杂连接的帮助。

我有 4 个表(recipes、recipes2tips、tips 和 tips2recipes),列名如下:

食谱 = id、名称、描述、视频

recipes2tips = id,食谱,小费

提示 = id、名称、描述、视频

Tips2recipes = id、小费、食谱

我正在尝试显示与每个食谱相关的所有提示,其中 recipes.id 将是加入因素。问题是所有的tips id 都等于recipes2tips.tip 和tips2recipes.tip。

这是我的第一次尝试,但它缺少一些东西:PHP 代码:[选择]

选择tips.id,tips.name,recipes2tips.recipe,recipes2tips.tip,recipes.id FROM Tips,recipes2tips,recipes wheretips.id = recipes2tips.tip;

任何建议都会很棒。

谢谢

4

1 回答 1

2

You are missing a join condition on your tables.

If you use proper join syntax (with an on clause), then you are much less likely to make this error:

SELECT tips.id, tips.name, recipes2tips.recipe, recipes2tips.tip, recipes.id
FROM tips join
     recipes2tips
     on tips.id = recipes2tips.tip
     recipes
     on recipes.id = recipes2tips.recipe ;
于 2013-07-30T02:10:08.513 回答