mysql查询报错Subquery returns more than 1 row 50
this_.site_id as site4_15_0_, this_.title as title15_0_, this_.path as path15_0_, this_.url
as url15_0_, this_.word as word15_0_, this_.score as score15_0_, this_.found_time as found10_15_0_,
this_.status as status15_0_, this_.isshow as isshow15_0_, this_.add_time as add13_15_0_, this_.add_user_id
as add14_15_0_, this_.update_time as update15_15_0_, this_.update_user_id as update16_15_0_, this_.source_ip as source17_15_0_,
(select o.id from done_page o where o.suspect_page_id = this_.id)
as formula0_0_,
(SELECT _ip.name FROM ip_segment _ip WHERE ( SELECT cc.ip
FROM crawl_site cc WHERE cc.id=this_.site_id)>=_ip.start_ip
AND ( SELECT cc.ip FROM crawl_site cc WHERE cc.id=this_.site_id) <=_ip.end_ip)
as formula1_0_ from suspect_page this_ where (this_.status<3 and this_.theme_id=1 and
this_.status=0 and this_.found_time>='2013-01-01' and this_.found_time<='2014-06-27' and site_id not in
(select site_id from site_list where type=0 or type=2) and this_.isshow=1) order by
this_.found_time desc, this_.score desc
mysql 查询报错Subquery returns more than 1 row 哪位帮忙看看 展开
MySQL报Subquery returns more than 1 row这个错误的意思是指子查询的结果多于一行。
解决方法:在子查询的条件语句末尾加 limit 1 。
例如:WHERE ( SELECT cc.ip FROM crawl_site cc WHERE cc.id=this_.site_id)>=_ip.start_ip
用这种条件,WHERE 后边的子查询(SELECT...)里面结果只能是1条,多了就会报“Subquery returns more than 1 row”这样的错误。
扩展资料:
MySQL管理工具:可以使用命令行工具管理 MySQL 数据库(命令 mysql 和 mysqladmin),也可以从 MySQL 的网站下载图形管理工具 MySQL Administrator, MySQL Query Browser 和 MySQL Workbench。
phpMyAdmin是由 php 写成的 MySQ L资料库系统管理程程序,让管理者可用 Web 界面管理 MySQL 资料库。
phpMyBackupPro也是由 PHP 写成的,可以透过 Web 界面创建和管理数据库。它可以创建伪 cronjobs,可以用来自动在某个时间或周期备份 MySQL 数据库。
另外,还有其他的 GUI 管理工具,例如 mysql-front 以及 ems mysql manager, navicat等等。
参考资料:百度百科——mySQL
意思是指子查询的结果多于一行。
WHERE ( SELECT cc.ip
FROM crawl_site cc WHERE cc.id=this_.site_id)>=_ip.start_ip
用这种条件,(SELECT。。。) 里面结果只能1条,多了就会“Subquery returns more than 1 row
”
解决方法:在子查询的条件语句末尾加 limit 1 。
以select * from table1 where table1.colums=(select columns from table2);这个sql语句为例。
1、如果是写入重复,去掉重复数据。然后写入的时候,可以加逻辑判断(php)或者外键(mysql),防止数据重复写入。
2、在子查询条件语句加limit 1,找到一个符合条件的就可以了
select * from table1 where table1.colums=(select columns from table2 limit 1);
3、在子查询前加any关键字
select * from table1 where table1.colums=any(select columns from table2);
扩展资料:
解决思路
子查询多了一行,众所周知这个子查询的查询结果是只能有一行。那么现在知道了就根据报错提示找到相应的mapper.xml文件的那个sql语句里纠错。首先:
SELECT '' AS bugID,A.`SUMMARY` AS `describe`,
(SELECT CONCAT(last_name ,first_name) FROM cwd_user WHERE user_name = A.`ASSIGNEE`) AS liablePerson,
(SELECT CONCAT(last_name , first_name) FROM cwd_user WHERE user_name = A.`REPORTER`) AS testLiablePerson ,
c.`pname` AS `status`,
(SELECT email_address FROM cwd_user WHERE user_name = A.`REPORTER`) AS emailAddressTest ,
(SELECT email_address FROM cwd_user WHERE user_name = A.`ASSIGNEE`) AS emailAddressDev
FROM `jiraissue` a, project b, issuestatus c
WHERE
a.`PROJECT` = b.`ID` AND a.`issuestatus` = c.`ID`
AND a.issuenum = #{bugID,jdbcType=VARCHAR}
AND b.`pkey` = #{projectName,jdbcType=VARCHAR}
看得出这里有四个子查询,然后把select的条件变成*查出来到底要什么。得到结果根据assignee和reporter的结果分别将子查询查一下发现根据报错的条件查发现是第二条有重复,这四条都会出现这个问题,所以优化一下在子查询上加个limit条件只用子查询结果的第一条就可以了。
应该是以下两个地方的问题
1.select o.id from done_page o ,这个的suspect_page_id,是否唯一?如果不唯一,需要limit 1;
2.SELECT _ip.name FROM ip_segment,这个表,在startip 和endip之间获取到的那么是否唯一,不唯一需要limit 1
FROM crawl_site cc WHERE cc.id=this_.site_id)>=_ip.start_ip
用这种条件,(SELECT。。。) 里面结果只能1条,多了就会“Subquery returns more than 1 row
”