两种方案:
1. 利用CONCAT(fromPartyId,partyId) 拼接的字符串做唯一性限制
insert into relation
(fromPartyId, partyId, isDelete, inputDate, inputMan, updateDate, updateMan)
select fromPartyId, partyId, isDelete, inputDate, inputMan, updateDate, updateMan from car where isDelete = 0
and CONCAT(fromPartyId,partyId) not in(
select concat(fromPartyId,partyId) from relation
)
2. 利用NOT EXISTS,查询整条数据,做唯一性查询
insert into relation
(fromPartyId, partyId, isDelete, inputDate, inputMan, updateDate, updateMan)
select fromPartyId, partyId, isDelete, inputDate, inputMan, updateDate, updateMan from car where isDelete = 0 and NOT EXISTS (
select fromPartyId, partyId, isDelete from relation where isDelete = 0
);