内连接和重复

时间:2017-01-30 09:42:31

标签: mysql

我正在尝试将5个表连接在一起,这会带回每行的多个副本,有时结果集将是150多行,这是不可预期的,我希望介于5-7之间

SELECT DISTINCT
a.user_name, a.date_added, a.guide_title, a.guide_summary, a.before_photo, a.after_photo, 
b.product_id,
c.step_number, c.photo, c.photo_caption, c.step_title, c.step_description,
d.tip_text,
e.product_name, e.page_address

FROM customer_stories AS a

INNER JOIN customer_stories_products_used AS b ON a.unique_id = b.story_id
INNER JOIN customer_stories_steps AS c ON a.unique_id = c.story_id
INNER JOIN customer_stories_tips AS d ON a.unique_id = d.story_id
INNER JOIN products AS e ON b.product_id = e.product_id

WHERE a.unique_id = 87

我也尝试过GROUP BY,但这只会带回一行

编辑: 一些预期结果应该是什么信息:

每个customer_story可能有多个步骤(表c),多个提示(表d)和使用的多个产品(表b),所使用的每个产品都应该从产品表(e)中带回一些信息。

返回的每一行都会带回(表a)中始终相同的所有数据,并且还会多次包含其他表中的数据

0 个答案:

没有答案
相关问题