以下是我选择所有收藏以及image_name
SELECT
cushbu_art.image_name,
cushbu_user_collections.collection_name
FROM
cushbu_art
JOIN cushbu_art_collections ON cushbu_art.id = cushbu_art_collections.art_id
LEFT JOIN cushbu_user_collections ON cushbu_user_collections.id = cushbu_art_collections.collection_id
现在我想从cushbu_art
表中仅选择3行(即需要对此JOIN cushbu_art_collections ON cushbu_art.id = cushbu_art_collections.art_id
应用限制)
我找到了this问题的解决方案,但我无法理解它的解决方案
更新
当前查询返回此
collection_name image_name
test-collection test1.jpg
test-collection test2.jpg
test-collection test3.jpg
hello-collection hello.jpg
集合名称test-collection
重复三次因为子表(cushbu_art)包含一个集合的三个图像
所以我想在cushbu_art.image_name
预期输出
collection_name image_name
test-collection test1.jpg
test-collection test2.jpg
hello-collection hello.jpg
这是我最新的查询
SELECT
cushbu_art.image_name,
cushbu_user_collections.collection_name
FROM
cushbu_art
JOIN cushbu_art_collections ON cushbu_art.id =(
SELECT
id
FROM
cushbu_art
WHERE
cushbu_art.id = cushbu_art_collections.art_id
LIMIT 1
)
LEFT JOIN cushbu_user_collections ON cushbu_user_collections.id = cushbu_art_collections.collection_id