• You have to serialize the access to both tables at the same time, then get your max, do what you need and then commit the transaction letting others access it. There is no other way. If you don't serialize access, then you'll end up with duplicates if many people access the table at the same time performing the same action. Simple as that.