Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sqlite

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 sqlite databases at the same time, each having the same column names, and in the end, I want to append the five tables in the five databases together into one table. What is the way to do this?

like image 721
md1630 Avatar asked May 17 '15 21:05

md1630


People also ask

How do I merge two tables in SQLite?

Syntax. The syntax for the SQLite CROSS JOIN is: SELECT columns FROM table1 CROSS JOIN table2; NOTE: Unlike an INNER or OUTER join, a CROSS JOIN has no condition to join the 2 tables.

How do I combine data from multiple tables into one table in SQL?

Multiple tables can be merged by columns in SQL using joins. Joins merge two tables based on the specified columns (generally, the primary key of one table and a foreign key of the other).

Does SQLite support concurrency?

Overview. Usually, SQLite allows at most one writer to proceed concurrently. The BEGIN CONCURRENT enhancement allows multiple writers to process write transactions simultanously if the database is in "wal" or "wal2" mode, although the system still serializes COMMIT commands.


1 Answers

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.

like image 140
Phantômaxx Avatar answered Sep 17 '22 12:09

Phantômaxx