[Android General] Blue-rayer:
I spent 2 or 3 days working on merging 2 database so I just wanted to explain my steps for whoever needs it. Page 8 has a lot of great info honestly.

What I had:

- my historical database linked to phone number 1

- a new database linked to phone number 2 - created as I was temporarily unable to access my phone number 1

Goal: merge both database into one and linked to my phone number 1

I initially assumed that I had to make a copy of all WhatsApp data in my phone 1 and then on my phone 2 switch number back to 1 so that the database would be mergeable. However, after spending quite some time looking at the architecture of the database it seems this is totally unnecessary and makes the process longer as I did countess recovery of either database (and you wait longer and longer for the verification code from WhatsApp). What identifies you in the database and more specifically in the 'messages' table is the column 'key_from_me' where 1 means you sent the message. The column that identifies in which group chat or single person chat the message belongs to is 'key_remote_jid'.

Anyway so if you have 2 phone with 2 DB you want to merge here is how to do it (repeat on each phone)

0) Make sure you run WhatsApp with the same version on each phone so that the database architecture is the same

1) WhatsApp => Settings => Chats => Chat backup; set backup to Google Drive to Never then click on Back up

This will make a local backup

2) Find your local backup. Before Android 11 the backup is located in your Home directory / WhatsApp. Since Android 11 it is located in HOME/Android/media/com.whatsapp/WhatApp

3) Check in WhatsApp/Databases that you have msgstore.db.crypt14 (or cryptXY depending on your version of whatsapp)

4) Save the WhatsApp directory somewhere safe in case of accident (safe means on your computer NOT YOUR PHONE)

if you miss this step and then lose all your data do not come crying.

5) Uninstall WhatsApp and do not check the keep data checkbox. The data they talk about here is stored in the internal SQLite database of the app, you do not have access to it and you cannot keep this DB as it will conflict in the next steps.

6) Install a whatsapp mod. I tried all 3 from this webpage but only Fouad WA ended up working for me.

7) if you have Android 11 or above Move your WhatsApp folder in the Home directory (that's where the moded app looks for its data)

8) Launch the mod, verify your phone number, then whatsapp should see you have a backup and ask you if you want to restore it. Do that

9) Once your WhatsApp data is restored

Click on the 3 dots on the top right corner

Pick FMMods -> Universal -> Backup and restore -> Backup WhatsApp Data

this backup is saved in HOME/WhatsApp/yoBackup/com.whatsapp

10) Check in HOME/WhatsApp/yoBackup/com.whatsapp/databases that you msgstore.db This is your database decrypted!

11) Copy that yoBackup on your computer

Now to merge the database. I tried using the jar mentioned in page 1 but it failed to run on my computer I was getting the error "java.lang.SecurityException: Prohibited package name: java.sql". So I recompiled the code and got it to run but it would fail to merge the database, checked the result and it really didn't merge any texts. In the end I manually did it.

12) Install DB Browser for SQLite

13) Run the app, Open Database and pick your yoBackup/com.whatsapp/databases/msgstore.db file

14) Click on Browse Data then pick the table 'messages' in the dropdown on the left

Only on one of your 2 DBs :

15) Remove the duplicate messages (select rows and click on the icon 'Delete the current record')

16) Copy either all the rows or go block by block and then Right click on the selection => Copy as SQL

17) Go to other DB, switch from Browse Data to Execute SQL

18) Paste the content - you should have something like

INSERT INTO "main"."messages" ("_id", "key_remote_jid", "key_from_me", "key_id", "status", .... many more tables)

VALUES ('10', '10000000000@s.whatsapp.net', ..... many values)

18) Click on the Execute All button. If this failed it means you are trying to insert rows that already exists, so you need to go back to step 15 and remove those duplicates.

After this step you have merge all your messages in one DB, so you can save your changes and close the database.

So now one of your two yoBackup folder should have a msgstore.db with all your messages.

19) Copy this file back to the yoBackup directory on the phone where you want to recover all your messages (replace the smaller msgstore.db)

20) Uninstall, Reinstall the moded WhatsApp (or go to your android settings => Application, find your app, Storage, Clear Storage)

21) Launch the app and click on the restore button (before verifying your phone number; the mod looks for yoBackup and then restore the info in it)

22) Complete the rest of the WhatsApp setup

23) Now all your messages are in one database !

If you want to run the official WhatsApp app keep going:

24) make a local backup (see step 1); check for a backup saved in HOME/WhatsApp/Databases ==> This creates an encrypted database that we can restore in the official app !

25) Uninstall the mod and install WhatsApp (official)

26) Move the WhatsApp folder back to its original location (undo step 7)

27) Launch WhatsApp, verify your number and if the application detects a backup restore it and you're DONE !!!

Restoring the encrypted merged DB in the official time took me a day!! It seems like it wasn't recognized it as a legit DB and thus wouldn't let me restore it. To trick WhatsApp into restoring it I did the following.

28) Wipe WhatsApp internal storage one more time (like in step 20)

29) Move your encrypted database away from WhatsApp folder (move msgstore.db.crypt14 to your download folder for instance)

30) Copy either of the backup you made in step 1 (those backups were made with untampered data and official app) and place it in the WhatsApp/Databases folder

31) Launch again the app, verify your number and now you shoud see WhatsApp telling you it found a backup to restore!

32) Do not click on restore, instead go back to your File manager and remove the database you copied in step 30 and undo step29, place it back to the databases folder!

33) Go back to WhatsApp and now when you will click on restore the backup it will restore it !!

DONE

Thanks to all of those who posted before me, I couldn't have made it without y'all :)

maybe I'll do a video to explain all that 😅