'How to update multiple queries in a single query
I want to count the no. Of yes in Table 1 :chk1

And store it in a different table
Table 2: chk2

The php code i am trying is
<?php
$connect = mysqli_connect("localhost", "root", "", "vsmsdb1");
$query1 ="UPDATE chk2 t1 SET t1.qty = (select count(*) from chk1 t2 where t2.qw = 'yes' && t1.name = 'qw')";
$result = mysqli_query($connect, $query1) or die(mysqli_error($connect));
?>
<?php
$conn = mysqli_connect("localhost", "root", "", "vsmsdb1");
$query2 ="UPDATE chk2 t1 SET t1.qty = (select count(*) from chk1 t2 where t2.as = 'yes' && t1.name = 'as')";
$result = mysqli_query($conn, $query2) or die(mysqli_error($conn));
?>
Bt running this php code is only updating one of the query that is only a single column is getting affected How do i update all the columns of table2: chk2 counting the no. Of 'yes' from table1: chk1
Of you may assist pl It can be a single update query or multiple query so that table2: chk2 gets updated in a single php file.
Solution 1:[1]
UPDATE chk2 t1
SET t1.qty = (select count(*) from chk1 t2 where t2.qw = 'yes' && t1.name = 'qw' OR t2.zx = 'yes' && t1.name = 'zx' OR t2.we = 'yes' && t1.name = 'we')
Using an OR in between queries will do the job
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dharman |
