I have two tables that are identical in structure. Table1
holds moderated data, table2
holds data that still has not been moderated.
Table 1
+------+-----------+-----------------+--------+-----------+----------+ | "id" | "name" | "description" | "type" | "country" | "status" | +------+-----------+-----------------+--------+-----------+----------+ | "1" | "Title 1" | "Description 1" | "1" | "US" | "0" | | "2" | "Title 2" | "Description 2" | "1 " | "UK" | "0" | +------+-----------+-----------------+--------+-----------+----------+
Table 2
+------+-----------+-----------------+--------+-----------+----------+ | "id" | "name" | "description" | "type" | "country" | "status" | +------+-----------+-----------------+--------+-----------+----------+ | "1" | "Title 1" | "Description 1" | "1" | "US" | "2" | | "2" | "Title 2" | "Description 2" | "1 " | "UK" | "2" | +------+-----------+-----------------+--------+-----------+----------+
I'm trying to update the column status
in both the tables using a single sql. Actually, a moderator updates only table2
since that's the table available to him.
When table2
two gets updated, cantable1
be updated at the same time? Using a single sql? Right now, I'm using 2 different convetional sql statements for this.
Right now I do like this:
UPDATE table2 set status = 0 where id = spid and country = spcountry;//Update table2 first
UPDATE table1 a
INNER JOIN table2 b
ON a.id = b.id and a.country = b.country
SET a.status = b.status
WHERE a.id=spid;
What I hope to do: Example
$status = 0;//php
update table1, table2 set status = $status where id=1 and conuntry = 'us' in table1 and table2.//The id and country need to be the same in both tables.