mysql - SQL Query to update data from 2 tables into another one -


i have table_a want update data 2 other tables.

table_a +----+---------+------------+-------+ | id |  user   |    date    | valid |  +----+---------+------------+-------+ | 10 | bob     |            |       | | 11 | joe     |            |       | | 12 | joe     |            |       | | 13 | pete    |            |       | | 14 | bob     |            |       |  +----+---------+------------+-------+ 

the date comes table_b table_b.rel_id = table_a.id

table_b +----+----------+----------+ | id |  rel_id  |  date    |  +----+----------+----------+ | 30 |    8     | 10/10/11 | | 31 |    9     | 10/10/11 | | 32 |   10     | 10/10/11 | | 33 |   11     | 10/10/11 | | 34 |   12     | 10/10/11 | | 35 |   13     | 10/10/11 | | 36 |   14     | 10/10/11 |         +----+----------+----------+ 

and valid comes table_c table_c.rel_id = table_a.id

table_c +----+----------+----------+ | id |  rel_id  |  valid   |  +----+----------+----------+ | 40 |   10     |   yes    | | 41 |   11     |   no     | | 42 |   12     |   yes    | | 43 |   13     |   no     | | 44 |   14     |   yes    | | 45 |   15     |   no     | | 46 |   16     |   yes    |         +----+----------+----------+ 

how can done sql-query?

you can join tables using inner join.

update  table_a         inner join table_b b             on a.id = b.rel_id         inner join table_c c             on a.id = c.rel_id set     a.date = b.date,         a.valid = c.valid 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -