加入问题 - 如何每行仅返回1个外部联接

时间:2013-10-08 19:48:04

标签: join

我不认为我的标题很好地解释了:)

我有一个查询,它有很多连接。

SELECT
sof_slot_games.launch_date,
sof_slot_games.game_name,
sof_reviews.review_content,
sof_slot_games.slot_game_id,
sof_slot_game_details.no_of_reels,
sof_slot_game_details.paylines,
sof_reviews.reg_timestamp,
sof_developers.developer_name,
sof_slot_games.game_slug,
sof_slot_game_images.game_image
FROM
sof_reviews
Inner Join sof_slot_games ON sof_slot_games.slot_game_id = sof_reviews.slot_game_id
Inner Join sof_slot_game_details ON sof_slot_games.slot_game_id = sof_slot_game_details.slot_game_id
Inner Join sof_developers ON sof_slot_games.developer_id = sof_developers.developer_id
left outer Join sof_slot_game_images ON sof_reviews.slot_game_id = sof_slot_game_images.slot_game_id
WHERE
sof_slot_game_images.image_type_id =  '3'
ORDER BY
sof_slot_games.launch_date DESC
limit 0,20

问题是我想每行只返回1个game_image。游戏本身基本上是launch_date最近的20场比赛。但是如果我加入game_image(type = 3),那么如果该游戏有多个图像,它将为同一个游戏带回多行。

我想真正选择最近的20场比赛,然后为每场比赛拉回第一张图片。这是进入前20场比赛的RSS Feed,这就是我想这样做的原因(万一有人想知道):)

我一直试图解决这个问题......我知道我以前做过这件事,但我的大脑并没有提醒我做了什么:)

谢谢!

0 个答案:

没有答案