2013-07-04 48 views
0

好傢伙,我有與下面的查詢mysql的這個錯誤,我不知道在哪裏做的錯誤,感謝你的幫助:)#1241 - 操作數應該包含1列(s)如何解決?

SELECT a.*,b.*,users.*, 
    (SELECT p.msg_text,p.occured_at 
    FROM message_private p 
    WHERE p.group_id=a.group_id 
    ORDER BY p.occured_at DESC LIMIT 1) as message, 
    f.countf,message.occured_at 
FROM message_group a 
INNER JOIN message_group b ON a.group_id=b.group_id 
INNER JOIN users ON users.profile_id = b.profile_id 
LEFT JOIN 
(
    SELECT COUNT(profile_id) countf, id_group 
    FROM message_view 
    WHERE profile_id = 'sN07X2' 
    GROUP BY id_group 
) f 
    on f.id_group = b.group_id 
WHERE a.profile_id = 'sN07X2' 
    AND b.profile_id != a.profile_id 
    AND countf > 0 
ORDER BY p.occured_at DESC 
LIMIT 9 

回答

1

在您的查詢的字段列表

SELECT a.*,b.*,users.*, 
    (SELECT p.msg_text,p.occured_at 
    FROM message_private p 
    WHERE p.group_id=a.group_id 
    ORDER BY p.occured_at DESC LIMIT 1) as message, 
    f.countf,message.occured_at 

這會將子查詢的結果用作message

但是,子查詢選擇兩列。

+0

+1想一想 – Stephan

1

此:

(SELECT p.msg_text,p.occured_at 
    FROM message_private p 
    WHERE p.group_id=a.group_id 
    ORDER BY p.occured_at DESC LIMIT 1) as message 

應該返回1個值,並將其返回2,這就是爲什麼出現錯誤

解決方案1:

CONCAT(p.msg_text,p.occured_at) 

解決方案2:

有2子查詢一個用於p.msg_text,另一個用於p.occured_at

相關問題