Count in mysql update mysql query, error support

Hi, you need an update starting from ..

SELECT tA.id, count(*) c FROM tA join tA ON tB.id = tA.id where tA.id = 5 GROUP BY tA.id having c > 1; 

I have a relational model for many. but you need to enable the account in the update

  UPDATE tA join tA ON tB.id = tA.id set cnt = 5; 

assuming this is a counting result

where 'c' is the first selection counter ... maybe.

 UPDATE tA join tA ON tB.id = tA.id set cnt = (SELECT count(*) c FROM tA join tA ON tB.id = tA.id WHERE tA.id = 5 GROUP BY tA.id having c > 1); 

say query syntax and not supported .. thnk

+4
source share
1 answer
 UPDATE tA INNER JOIN ( SELECT tA.id, COUNT(*) totalCount FROM tA INNER JOIN tB ON tB.id = tA.id WHERE tA.id = 5 GROUP BY tA.id HAVING COUNT(*) > 1 ) b ON tA.id = b.id SET tA.cnt = b.totalCount 
+1
source

Source: https://habr.com/ru/post/1481290/


All Articles