SQL INSERT INTO from multiple tables

前端 未结 7 650
清歌不尽
清歌不尽 2020-12-02 12:17

this is my table 1:

NAME       AGE        SEX        CITY             ID

Clara      22         f          New York         1
Bob        33         m                 


        
7条回答
  •  醉梦人生
    2020-12-02 13:06

    Here is an short extension for 3 or more tables to the answer of D Stanley:

    INSERT INTO other_table (name, age, sex, city, id, number, nationality)
    SELECT name, age, sex, city, p.id, number, n.nationality
    FROM table_1 p
    INNER JOIN table_2 a ON a.id = p.id
    INNER JOIN table_3 b ON b.id = p.id
    ...
    INNER JOIN table_n x ON x.id = p.id
    

提交回复
热议问题