Running select statement inside an update query
You could use a non-correlated subquery to do the work for you:
1. UPDATE tbl_1 dest,
(SELECT count(*) as cnt_n,userid FROM tbl_2 group by userid) src
SET dest.cnt = src.cnt_n
where dest.id = src.userid
2. UPDATE tbl_taxclasses c
INNER JOIN
( SELECT COUNT(regionsid) AS n FROM tbl_taxclasses_regions GROUP BY classid ) r
USING(classid)
SET
c.regionscount = r.n
WHERE
c.classid = 1
3. UPDATE `tbl_taxclasses`
SET `regionscount` = (
SELECT COUNT(regionsid) AS `num`
FROM `tbl_taxclasses_regions`
WHERE classid = 1)
WHERE classid = 1 LIMIT 1
4.UPDATE table1 dest, (SELECT * FROM table2 where id=x) src
SET dest.col1 = src.col1 where dest.id=x ;
0 comments:
Post a Comment