Slightly more polished sql merger