我有一个包含游戏,文章(评论+预览)和视频(视频评论+视频预览)的数据库。我有一个身份233
的游戏,我想找一个评论,一个预览,一个视频评论和视频预览(如果存在的话)。
为此,我使用以下查询:
SELECT (SELECT article_url
FROM articles
WHERE articles_game_id = 233
AND artikel_sort = 'review'
AND article_online = 1
ORDER BY article_datetime DESC
LIMIT 1) AS review,
(SELECT article_url
FROM articles
WHERE articles_game_id = 233
AND artikel_sort = 'preview'
AND article_online = 1
ORDER BY article_datetime DESC
LIMIT 1) AS preview,
(SELECT trailer_url
FROM trailers
WHERE trailer_game_id = 233
AND trailer_sort = 'video review'
AND trailer_online = 1
ORDER BY trailer_datetime DESC
LIMIT 1) AS videoreview,
(SELECT trailer_url
FROM trailers
WHERE trailer_game_id = 233
AND trailer_sort = 'video preview'
AND trailer_online = 1
ORDER BY trailer_datetime DESC
LIMIT 1) AS videopreview
FROM articles
但是,此查询有两个问题:
有人知道解决这个问题的有效方法吗?非常感谢任何帮助!