mysql error: sub-query returns more than 1 row

半腔热情 提交于 2019-12-13 20:45:17

问题


I am using two tables here projections_report p and access_rights a. I can't find out why I am getting the error:

subquery returns more than one row

(case when paramChannel='AllC' then p.gl_sal_chan in 
      (case when dc_lob=0 then (select distinct pr.gl_sal_chan from 
          projections_report pr) else (select distinct pr1.gl_sal_chan
                 from projections_report pr1 where pr1.gl_sal_chan 
                 in (select distinct a.gl_sal_chan from access_rights 
                 a where a.userid= paramUserId)) end) 
 else p.gl_sal_chan = paramChannel end)

I tried using all and any keywords. Please help.

Thanks in advance.


回答1:


USE LIMIT in sub queries to return only one record as you are using distinct, it might return more than one record




回答2:


I tried to do it in another way and got it right. Firstly I changed the statement in else condition of second case statement to

(select distinct gl_sal_chan from access_rights where userid = paramUserid)

as both return the same result(my bad) and secondly I changed the entire condition to

(case when (paramChannel = 'AllC' && dc_lob = 0) then '%' = '%' else 
    (case when (paramChannel='AllC' && dc_lob != 0) then 
    gl_sal_chan in (select distinct gl_sal_chan from access_rights where userid = paramUserid) 
else gl_sal_chan= paramChannel end)end)

Anyway Thanks @all :)



来源:https://stackoverflow.com/questions/12072481/mysql-error-sub-query-returns-more-than-1-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!