Creating a new table from two or more existing tables (MySQL)

后端 未结 1 1361
别那么骄傲
别那么骄傲 2021-01-29 01:34

Question:

Is it possible to create a table in mySQL from two or more existing tables?

Details:

Can I create a table like so:

CREATE T         


        
1条回答
  •  [愿得一人]
    2021-01-29 01:42

    How about:

    CREATE TABLE IF NOT EXISTS USER SELECT * FROM USERNAME, USERAGE WHERE FALSE;
    

    You can furthermore specify any indexes you require in the new table prior to the SELECT keyword, or rename columns/select some subset as usual on the right of SELECT:

    CREATE TABLE IF NOT EXISTS USER (PRIMARY KEY(UNAME)) SELECT NAME AS UNAME -- etc
    

    If you want to combine all columns of the same name, just use NATURAL JOINs in your SELECT.

    See CREATE TABLE ... SELECT for more information.

    0 讨论(0)
提交回复
热议问题