I need to merge two tables in sqlite based on a common column. The problem is both the tables belong to different databases. So, what would be an efficient way to merge the tables here?
A sample table would be like this with the desired result. But the problem is these two tables are in different databases.
Table 1: Employee_Pro_Profile
Columns: Emp_Id, Emp_Name, Emp_Sal
Table 2: Employee_Personal_Profile
Columns: Emp_Id, Emp_Home_Address, Emp_Phone
Resulting Table: Employee_Complete
Columns: Emp_Id, Emp_Name, Emp_Sal, Emp_Home_Address, Emp_Phone
Run Code Online (Sandbox Code Playgroud)
Okey first you have to attach the databases, to your current connection.
SQLite give you this by using ATTACH.
The ATTACH DATABASE statement adds another database file to the current database connection. ATTACH LINK
Run this:
attach database DatabaseA.db as DbA;
attach database DatabaseB.db as DbB;
Run Code Online (Sandbox Code Playgroud)
Now you can reference the databases as you do with tables...
select
*
from
DbA.Table1 A
inner join
DbB.Table2 B on B.Emp_Id = A.Emp_Id;
Run Code Online (Sandbox Code Playgroud)
There is a limit to the number of databases that can be simultaneously attached to a single database connection.
检查您的设置是否出了问题,标志是:
Run Code Online (Sandbox Code Playgroud)#define SQLITE_LIMIT_ATTACHED 7 // SQLITE_LIMIT_ATTACHED - The maximum number of attached databases.
归档时间: |
|
查看次数: |
5008 次 |
最近记录: |