最近在做sql的血缘关系图,在将输入表和输出表存进MySQL数据表时, 担心有重复记录,后面画图需要处理,故在插入数据前先判断数据是否存在。
详细SQL:
<insert id="insertSysKinshipMaps" parameterType="SysKinshipMap">
INSERT INTO sys_kinship_map (parent_name, children_name)
SELECT #{parentName}, #{childrenName} FROM DUAL
WHERE NOT EXISTS (
SELECT parent_name, children_name FROM sys_kinship_map
WHERE parent_name = #{parentName} AND children_name=#{childrenName}
)
</insert>