Sync one database from 2 avoiding duplicates

I have three databases from which I need to set up the proper sync:

  • Database Students 20-21: list of all the students from 2020-2021 school year (including field school year 20-21, unique student ID and photos (attachment)

  • Database Students 21-22: list of all the students from 2021-2022 school year (including field school year 21-22, a unique student ID and a field Indicating if a student is new. (no photo yet)

  • Database Students All Years: I would like to sync the Database 2020-21 and then the database 2021-22. This database is not syncing the field “New student” as this database is to collect information through the year. the field School year becomes “Last Year enrolled”.

Problem : avoiding duplicates
I would like to be able to sync the 2 first databases with the third one and avoid duplicates. For now if student ID xxxx is in database 2020-21, and he is re-enrolled so he is also in database 2021-22, then I have two occurrences in database All years.
How can I sync the database so if a student is in database 2020-21 and in database 2021-22, then the database All year keeps the record from database 2021-2022 with would have the most updated information