Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SQL内部查询-子查询返回超过1行_Java_Mysql - Fatal编程技术网

Java SQL内部查询-子查询返回超过1行

Java SQL内部查询-子查询返回超过1行,java,mysql,Java,Mysql,我收到的错误信息是 错误代码:1242 子查询返回超过1行 解决方案???您的内部查询 SELECT DISTINCT cmt.topic_id,ctt.description AS topic_name,cmrt.room_id,cmrt.family_id, crt.title AS room_name, ft.family_identifier AS family_name, upt.gender, cmt.postedby_userid, cmt.member_id, ut.pictu

我收到的错误信息是 错误代码:1242 子查询返回超过1行

解决方案???

您的内部查询

SELECT DISTINCT cmt.topic_id,ctt.description AS topic_name,cmrt.room_id,cmrt.family_id, crt.title AS room_name, ft.family_identifier AS family_name, upt.gender, cmt.postedby_userid, cmt.member_id, 
ut.picture_filename AS senderImage, 
ut.croppedpicture_filename AS senderCroppedImage, 
cmt.image AS imageUrl , 
cmt.message AS caption, 
cmrt.user_id, 
(SELECT COUNT(id) FROM `conversation_messages_tbl` a ,`conversation_msgreadstatus_tbl` b WHERE a.`message_id` = b.`message_id`
AND a.`topic_id` = b.`topic_id` AND  b.`is_read`= 0 AND b.`user_id`!= 27 GROUP BY b.`user_id`) countn
FROM conversation_messages_tbl cmt, 
conversation_topics_tbl ctt , 
conversation_msgreadstatus_tbl cmrt, 
conversation_rooms_tbl crt, family_tbl ft, 
user_profileinformation_tbl upt, 
user_tbl ut 
WHERE ctt.topic_id=cmt.topic_id AND cmrt.message_id=cmt.message_id
AND upt.user_id=cmt.postedby_userid AND crt.room_id=cmrt.room_id AND ft.family_id=crt.family_id 
AND ut.user_id=cmt.postedby_userid AND cmt.message_id=202 GROUP BY cmrt.user_id;

可以返回多行,因为它将返回每个不同用户id的计数,不同于27行(因为group by)。

子查询将返回多行,因为您使用了
group by b.user id
,并且查询和子查询之间没有条件

如果我的想法正确,
cmrt.user\u id
等于
b.user\u id
,您可以向子查询添加如下条件:

(SELECT COUNT(id) FROM `conversation_messages_tbl` a ,`conversation_msgreadstatus_tbl` b WHERE a.`message_id` = b.`message_id` AND a.`topic_id` = b.`topic_id` AND  b.`is_read`= 0 AND b.`user_id`!= 27 GROUP BY b.`user_id`) countn

不要运行返回超过1行的子查询。
(SELECT COUNT(id) FROM `conversation_messages_tbl` a   
`conversation_msgreadstatus_tbl` b WHERE a.`message_id` = b.`message_id`
AND a.`topic_id` = b.`topic_id` AND  b.`is_read`= 0 AND b.`user_id`!= 27 
b.`user_id`=cmrt.user_id) countn