mardi 5 juillet 2016

How to copy rows in sql?

this is my table 1:

NAME       CITY             ID
Clara      New York         1
Bob        Washington       2
Sam        Boston           3

this is my table 2:

NAME    Table1_ID  ID
 A        1        1
 B        1        2
 C        2        3
 D        2        4

this is my table 3:

NAME    Table2_ID   ID
 A_3        1        1
 B_3        2        2
 C_3        2        3
 C_3        3        4

I want copy row in table 1 where ID = 1 and also the all rows in Table 2 and Table 3 which are associated with table 1 so output will be :

Out put of table 1:

NAME       CITY             ID
Clara      New York         1
Bob        Washington       2
Sam        Boston           3
Clara      New York         4

Out put of table 2:

NAME    Table1_ID  ID
 A        1        1
 B        1        2
 C        2        3
 D        2        4
 A        4        5
 B        4        6

out put of table 3:

NAME    Table2_ID   ID
 A_3        1        1
 B_3        2        2
 C_3        2        3
 C_3        3        4
 A_3        5        5
 B_3        6        6
 C_3        6        7

Aucun commentaire:

Enregistrer un commentaire