2017-09-06 63 views
-3

我有使用按預期運行下面的查詢,最近的記錄的數量已經長大,不知它在返回#1242 - Subquery returns more than 1 row 解決方案的子查詢返回超過1行

SELECT `log`.id,log.account_id,log.type, 
(SELECT COUNT(*) FROM instagram_log as LIKES WHERE `account_id`=log.account_id AND `type`='like' AND log.target_account=LIKES.target_account AND `seen`=0) as has_liked, 
(SELECT COUNT(*) FROM instagram_log as Comments WHERE `account_id`=log.account_id AND `type`='comment' AND log.target_account=Comments.target_account AND `seen`=0) as has_commented, 
(SELECT information FROM instagram_log as Source WHERE `account_id`=log.account_id AND `type`='follow' AND log.target_account=Source.target_account AND `seen`=0) as source, 
(SELECT data FROM instagram_accounts WHERE `id`=log.account_id) as InstagramInfo 
FROM `instagram_log` as `log` WHERE `type` = 'follow_back' AND `account_id` IN('1', '5', '2') ORDER BY `id` DESC LIMIT 15 
+3

有什麼有關錯誤MESSA你不明白? –

+0

你知道哪個子查詢是問題嗎? –

回答

1

添加「LIMIT 1」它可以在選擇

1
SELECT `log`.id,log.account_id,log.type, 
(SELECT COUNT(*) FROM instagram_log as LIKES WHERE 
`account_id`=log.account_id AND `type`='like' AND 
log.target_account=LIKES.target_account AND `seen`=0) as has_liked, 
(SELECT COUNT(*) FROM instagram_log as Comments WHERE 
`account_id`=log.account_id AND `type`='comment' AND 
log.target_account=Comments.target_account AND `seen`=0) as has_commented, 
(SELECT information FROM instagram_log as Source WHERE 
`account_id`=log.account_id AND `type`='follow' AND 
log.target_account=Source.target_account AND `seen`=0 limit 1) as source, 
(SELECT data FROM instagram_accounts WHERE `id`=log.account_id limit 1) as 
InstagramInfo 
FROM `instagram_log` as `log` WHERE `type` = 'follow_back' AND `account_id` 
IN('1', '5', '2') ORDER BY `id` DESC LIMIT 15 

返回超過1行,或使用agregate功能(最大,最小,GROUP_CONCAT ...)子查詢試試這個..

相關問題