I have two tables in each of two dbs:
places: id, url (unique),
visits: id, place_id, timestamp, type.
I need to merge those databases:
There are one main database and one "to-merge". The unique data should be added to the main database (of course with new ids).
Source dbs may contain same
places
andvisits
rows but some of them can be with different ids.Two
visits
rows are equal when theirtimestamp
,type
columns andplaces.url
are equal.Two
places
rows are equal when theirurl
columns are equal.place_id
should be corrected for mergedvisits
.
I can attach databases with ATTACH ... AS ...
.
I've already done this with C# code but that solution seems to be a kind of overcomplicated (I have it on github). I'm wondering if it's possible to merge them with sql only? How would you do that?