sqlite append two tables from two databases that have the exact same schema

前端 未结 2 2054
醉话见心
醉话见心 2021-02-06 01:47

I\'m writing data into an sqlite database, but because the data set is very large, I\'m splitting the process into five pieces. As a result, I\'m writing to five different sqlit

相关标签:
2条回答
  • 2021-02-06 02:01

    You can use ATTACH to make the contents of another database file accessible in the same connection:

    ATTACH "/some/where/db2.sqlite" AS db2;
    INSERT INTO main.MyTable SELECT * FROM db2.MyTable;
    

    (The main database is always called main; opening a new database connection is the equivalent of ATTACH "filename" AS main.)

    0 讨论(0)
  • 2021-02-06 02:06

    You can use UNION or UNION ALL to merge 2 or more queries.

    Something like:

    SELECT Field1, Field2, Field3 FROM Table1
    UNION 
    SELECT Field1, Field2, Field3 FROM Table2
    

    You can use an INSERT INTO NewTableName (SELECT ...) to create a new table from that UNION.

    The ALL variant of the UNION clause includes the (eventual) duplicate records.

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