Create table (structure) from existing table

后端 未结 15 1404
遇见更好的自我
遇见更好的自我 2020-11-27 13:46

How to create new table which structure should be same as another table

I tried

CREATE TABLE dom AS SELECT * FROM dom1 WHERE 1=2

bu

15条回答
  •  遥遥无期
    2020-11-27 14:05

    Found here what I was looking for. Helped me recall what I used 3-4 years back.

    I wanted to reuse the same syntax to be able to create table with data resulting from the join of a table.

    Came up with below query after a few attempts.

    SELECT a.*
    INTO   DetailsArchive
    FROM   (SELECT d.*
            FROM   details AS d
                   INNER JOIN
                   port AS p
                   ON p.importid = d.importid
            WHERE  p.status = 2) AS a;
    

提交回复
热议问题