Fix UPSERT SELECT does not work with JOIN (github #596)