mysql - Update table1 with count from table1 when count is null -


i had query updated row in table1 count(*) table -

update t1 set a=(select count(b) t2 c=10 group c)) id=20 

the problem if there no entries in t2 c=10, query fails select returns null or nothing. there way make work if sub-select statement returns null?

p.s. have tried using ifnull, looks doesn't work.

one of mysql's many curiosities that, if 1 drops group by clause (mysql implicitly group rows if aggregate function used in absence of explicit group by clause), return aggregated results if there no underlying records; in case of count() function, returns result of 0 desired:

update t1 set a=(select count(*) t2 c=10) id=20 

see on sqlfiddle.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -