1

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:

  1. There are one main database and one "to-merge". The unique data should be added to the main database (of course with new ids).

  2. Source dbs may contain same places and visits rows but some of them can be with different ids.

  3. Two visits rows are equal when their timestamp, type columns and places.url are equal.

  4. Two places rows are equal when their url columns are equal.

  5. place_id should be corrected for merged visits.

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?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.