CREATE TABLE LIKE A1 as A2

后端 未结 5 841
猫巷女王i
猫巷女王i 2020-12-14 14:14

I want to create a new table with properties of an old table and without duplicates. I want to do something like this:

CREATE TABLE New_Users  LIKE Old_Users         


        
5条回答
  •  悲哀的现实
    2020-12-14 15:05

    Your attempt wasn't that bad. You have to do it with LIKE, yes.

    In the manual it says:

    Use LIKE to create an empty table based on the definition of another table, including any column attributes and indexes defined in the original table.

    So you do:

    CREATE TABLE New_Users  LIKE Old_Users;
    

    Then you insert with

    INSERT INTO New_Users SELECT * FROM Old_Users GROUP BY ID;
    

    But you can not do it in one statement.

提交回复
热议问题