First im mysql noob 😀
Ive tried searching but nothing that can help.
Im trying to update my database with this query.
UPDATE client SET cntr_limit=(SELECT fulltraffic from
(SELECT
client.id,
(SUM(ipacct.byteso)+SUM(ipacct.bytesi)) as fulltraffic
FROM client
LEFT JOIN ips ON client.id = ips.cid
LEFT JOIN ipacct ON ips.ip = ipacct.target
WHERE ipacct.tag = 1
GROUP BY client.id
) as x
) +322122547200 ;
Im getting Subquery returns more than 1 row.
I know the subquery cant have more than one row but i need to work with GROUP BY. If i remove GROUP BY query works but every client get the traffic calculated from all the ips,
instead of traffic calculated differently for every id.
If i use.
SELECT
client.id,
(SUM(ipacct.byteso)+SUM(ipacct.bytesi)) as fulltraffic
FROM client
LEFT JOIN ips ON client.id = ips.cid
LEFT JOIN ipacct ON ips.ip = ipacct.target
WHERE ipacct.tag = 1
GROUP BY client.id;
im getting
id fulltraffic
1 5100993724986
3 410550845834
4 790726628007
5 204212941099
6 440290245087
8 587044969960
if i remove GROUP BY im getting
id fulltraffic
1 487196626849368
Thanks in advance.
use
INinstead of=.and remove the last alias
+322122547200 ;but a better way to do it is to join the tables on
UPDATEstatement,