There are two solutions provided (see links at the bottom), but both fail in what i'm trying to do:
1. Given tables (identical) structure in databases like for example this:
DB1
Fruit--------------
| id | name |
--------------
| 1 | Apple |
| 2 | Lemon |
| 3 | Kiwi |
| 4 | Banana|
--------------
Juice
----------------
| id | name |
----------------
| 1 | Juice A |
| 2 | Juice B |
----------------
Recipe (Junction Table)
----------------------------
| id | juice_id | fruit_id |
----------------------------
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 1 |
| 4 | 2 | 3 |
----------------------------
DB2
Fruit---------------
| id | name |
---------------
| 1 | Kiwi |
| 2 | Lemon |
| 3 | Apple |
| 4 | Orange |
| 5 | Lime |
---------------
Juice
----------------
| id | name |
----------------
| 1 | Juice C |
| 2 | Juice D |
----------------
Recipe (Junction Table)
----------------------------
| id | juice_id | fruit_id |
----------------------------
| 1 | 1 | 1 |
| 2 | 1 | 3 |
| 3 | 2 | 2 |
| 4 | 2 | 4 |
----------------------------
2. convert them into this:
DB3
Fruit|----------------|
| id | name |
|----------------|
| 1 | Kiwi |
| 2 | Lemon |
| 3 | Apple |
| 4 | Orange |
| 5 | Lime |
| 6 | Banana |
------------------
Juice
|--------------|
| id | name |
|--------------|
| 1 | Juice A |
| 2 | Juice B |
| 3 | Juice C |
| 4 | Juice D |
----------------
Recipe (Junction Table)
----------------------------
| id | juice_id | fruit_id |
----------------------------
| 1 | 1 | 3 |
| 2 | 1 | 2 |
| 3 | 2 | 3 |
| 4 | 2 | 1 |
++++++++++++++++++++++++++++
| 5 | 3 | 1 |
| 6 | 3 | 3 |
| 7 | 4 | 2 |
| 8 | 4 | 4 |
----------------------------
Please notice that fruit id's changed accordingly, preserving relations despite change in fruit ID. ID is primary integer autoincrementing key, and Recipe contains two foregin keys (plus own primary integer autoincrementing key).
3. only two proposed solutions are:
a)
$sqlite3 database1.db '.dump' >> tmp
$sqlite3 database2.db '.dump' >> tmp
$sqlite3 database3.db '.import tmp'
$ #sometimes sqlite3 database3.db < 'tmp' instead of last row
from 4, and simmilar questions, and:
b)
$ sqlite3 newdb
attach 'b.db' as toMerge;
BEGIN;
insert into newdb select * from toMerge.sometable;
COMMIT;
Other answers ie. 1, 2, 3, 4, 5, 6, 7 just repeat same pattern. Perhaps 6 might be solution but i couldnt tell, the lenght of that query frightened me...
Moreover, as 1 states there is no gui compare & merge solution. At least besides 2011 sqlitecompare, which probably works in Windows anyway (i'm looking for Linux tool) Some opinions in 8 also confirm that hardly any userfriendly gui has merge option.
So, question is. How to merge sqlite DB in Linux, keeping relations, but not keeping duplicate values from tags / notes? I'd thought that keeping organized structure is the main reason for keeping things in database, but it seems I fail to understand, why should i keep two same fruits in one basket if combining from two baskets. My basket should contain unique fruits and recipies, I want to eat that kiwi :)