0

I have following three tables

Table1

+------+--------+
| GID  | Active |
+------+--------+
| 110  |  Yes   |
+------+--------+
GID is primary key

Table2

+------+--------+
| UID  | Active |
+------+--------+
| 110  |  Yes   |
| 110  |  Yes   |
+------+--------+

Table3

+------+--------+
| FID  | Active |
+------+--------+
| 110  |  Yes   |
| 110  |  Yes   |
+------+--------+

I want to update 3 tables with all the value of field Active to 'no' , how can I achieve this ? Your suggestions are highly appreciated, I hope the given information is subsequent to make a conclusion on this ?

Additional information :- Following is the query I am executing in table1 now.

  $id = 110;
  UPDATE table1 SET active = 'no' WHERE gid = {$id}"
Tom
  • 500
  • 3
  • 5
  • 16
  • Do you want to make all values of `Active` in all tables `No` unconditionally or there are some conditions? It is not quite clear from the question – Tigran Saluev Jul 22 '16 at 10:35
  • Possible duplicate of [MySQL, update multiple tables with one query](http://stackoverflow.com/questions/4361774/mysql-update-multiple-tables-with-one-query) – KaeL Jul 22 '16 at 10:38
  • @Tirgan .. I have edited the question, can you please check ? – Tom Jul 22 '16 at 10:40
  • @Tom So you want to modify rows with same IDs? – Tigran Saluev Jul 22 '16 at 10:41

1 Answers1

0

This is how to update all rows with given id:

UPDATE 
    Table1, Table2, Table3
SET 
    Table1.Active = 'No', 
    Table2.Active = 'No', 
    Table3.Active = 'No'
WHERE
    Table1.GID = Table2.UID
AND Table2.UID = Table3.FID
AND Table3.FID = 110;
Tigran Saluev
  • 3,351
  • 2
  • 26
  • 40