我有以下SQL查詢:重複條目連接語句
SELECT band.id bid, band.name, bandInfo.summary, bandImage.url bandImage,
user.id uid, user.username, userImage.url userImage
FROM bands AS band
INNER JOIN band_info AS bandInfo ON band.id = bandInfo.bid
LEFT JOIN band_image AS bandImage ON band.id = bandImage.bid
LEFT JOIN band_followers AS follower ON follower.bid = band.id
LEFT JOIN users AS user ON user.id IN (SELECT * FROM (SELECT user.id FROM users AS user, bands AS band, band_followers AS follower WHERE user.id = follower.uid) AS temp) AND user.activated = 1
LEFT JOIN user_info AS userInfo ON userInfo.uid = user.id
LEFT JOIN user_image AS userImage ON user.id = userImage.uid
WHERE (band.activated = 1) AND (bandInfo.language = 'fr')
ORDER BY band.name
返回我複製線。
目標是檢索所有用戶,如果存在的話,所有用戶都會遵循所有帶寬限制來執行一些分頁結果。
我需要檢索:
{
"table": "Table inconnue",
"rows":
[
{
"bid": 1,
"name": "Children Of Bodom",
"summary": "Children of Bodom est un groupe de metal finlandais. Les cinq membres du groupe sont originaires d'Espoo, une ville finlandaise voisine d'Helsinki. Le groupe ne s’appelle ainsi que depuis 1997, avant quoi il s’appelait Inearthed. La mascotte du groupe est affectueusement appelée Roy et représente l'image folklorique de la mort, la faucheuse. Il est présent sur toutes les couvertures d'albums jusqu'à présent. <a href="http://www.last.fm/music/Children+of+Bodom">Read more about Children of Bodom on Last.fm</a>.",
"bandImage": "http://userserve-ak.last.fm/serve/500/87864171/Children+of+Bodom+band.png",
"uid": 1,
"username": "everytimeicob",
"userImage": "xxxxxxxxx"
},
{
"bid": 1,
"name": "Children Of Bodom",
"summary": "Children of Bodom est un groupe de metal finlandais. Les cinq membres du groupe sont originaires d'Espoo, une ville finlandaise voisine d'Helsinki. Le groupe ne s’appelle ainsi que depuis 1997, avant quoi il s’appelait Inearthed. La mascotte du groupe est affectueusement appelée Roy et représente l'image folklorique de la mort, la faucheuse. Il est présent sur toutes les couvertures d'albums jusqu'à présent. <a href="http://www.last.fm/music/Children+of+Bodom">Read more about Children of Bodom on Last.fm</a>.",
"bandImage": "http://userserve-ak.last.fm/serve/500/87864171/Children+of+Bodom+band.png",
"uid": 2,
"username": "noob",
"userImage": "xxxxxxxx"
},
{
"bid": 2,
"name": "Veil Of Maya",
"summary": "Veil of Maya is a good band",
"bandImage": null,
"uid": 1,
"username": "everytimeicob",
"userImage": "xxxxxx"
}
]
}
但我檢索:
{
"table": "Table inconnue",
"rows":
[
{
"bid": 1,
"name": "Children Of Bodom",
"summary": "Children of Bodom est un groupe de metal finlandais. Les cinq membres du groupe sont originaires d'Espoo, une ville finlandaise voisine d'Helsinki. Le groupe ne s’appelle ainsi que depuis 1997, avant quoi il s’appelait Inearthed. La mascotte du groupe est affectueusement appelée Roy et représente l'image folklorique de la mort, la faucheuse. Il est présent sur toutes les couvertures d'albums jusqu'à présent. <a href="http://www.last.fm/music/Children+of+Bodom">Read more about Children of Bodom on Last.fm</a>.",
"bandImage": "http://userserve-ak.last.fm/serve/500/87864171/Children+of+Bodom+band.png",
"uid": 1,
"username": "everytimeicob",
"userImage": "xxxxxxxxx"
},
{
"bid": 1,
"name": "Children Of Bodom",
"summary": "Children of Bodom est un groupe de metal finlandais. Les cinq membres du groupe sont originaires d'Espoo, une ville finlandaise voisine d'Helsinki. Le groupe ne s’appelle ainsi que depuis 1997, avant quoi il s’appelait Inearthed. La mascotte du groupe est affectueusement appelée Roy et représente l'image folklorique de la mort, la faucheuse. Il est présent sur toutes les couvertures d'albums jusqu'à présent. <a href="http://www.last.fm/music/Children+of+Bodom">Read more about Children of Bodom on Last.fm</a>.",
"bandImage": "http://userserve-ak.last.fm/serve/500/87864171/Children+of+Bodom+band.png",
"uid": 1,
"username": "everytimeicob",
"userImage": "xxxxxxxxx"
},
{
"bid": 1,
"name": "Children Of Bodom",
"summary": "Children of Bodom est un groupe de metal finlandais. Les cinq membres du groupe sont originaires d'Espoo, une ville finlandaise voisine d'Helsinki. Le groupe ne s’appelle ainsi que depuis 1997, avant quoi il s’appelait Inearthed. La mascotte du groupe est affectueusement appelée Roy et représente l'image folklorique de la mort, la faucheuse. Il est présent sur toutes les couvertures d'albums jusqu'à présent. <a href="http://www.last.fm/music/Children+of+Bodom">Read more about Children of Bodom on Last.fm</a>.",
"bandImage": "http://userserve-ak.last.fm/serve/500/87864171/Children+of+Bodom+band.png",
"uid": 2,
"username": "noob",
"userImage": "xxxxxxxx"
},
{
"bid": 1,
"name": "Children Of Bodom",
"summary": "Children of Bodom est un groupe de metal finlandais. Les cinq membres du groupe sont originaires d'Espoo, une ville finlandaise voisine d'Helsinki. Le groupe ne s’appelle ainsi que depuis 1997, avant quoi il s’appelait Inearthed. La mascotte du groupe est affectueusement appelée Roy et représente l'image folklorique de la mort, la faucheuse. Il est présent sur toutes les couvertures d'albums jusqu'à présent. <a href="http://www.last.fm/music/Children+of+Bodom">Read more about Children of Bodom on Last.fm</a>.",
"bandImage": "http://userserve-ak.last.fm/serve/500/87864171/Children+of+Bodom+band.png",
"uid": 2,
"username": "noob",
"userImage": "xxxxxxxxx"
},
{
"bid": 2,
"name": "Veil Of Maya",
"summary": "Veil of Maya is a good band",
"bandImage": null,
"uid": 1,
"username": "everytimeicob",
"userImage": "xxxxxxxx"
},
{
"bid": 2,
"name": "Veil Of Maya",
"summary": "Veil of Maya is a good band",
"bandImage": null,
"uid": 2,
"username": "noob",
"userImage": "xxxxxxx"
}
]
}
這裏任何人都得到一個想法?我不得不限制用戶的結果,下面帶
是..但如果我使用極限,它會限制對樂隊,而不是users.id在band_followers – everytimeicob
不知道我的理解。如果我使用LIMIT,你的意思是?您的子查詢實際上並不需要,因爲您可以直接與bandfollower進行連接。 – Rahul
我想限制'LEFT JOIN users on user.id = follower.uid AND user.activated = 1'提供的結果,因爲我想爲每個樂隊做一些分頁,例如只有10個用戶,而不是全部 – everytimeicob