INSERT `locality` (province_id)
SELECT DISTINCT `province_id`
FROM `locality` localreturn
WHERE
NOT EXISTS (SELECT * FROM `locality` local
WHERE localreturn.province_id = local.province_id)
如果测试的查询通过了如何插入值? 正常的插入就像:
INSERT INTO `locality` (`province_id`) VALUES (1919)
答案 0 :(得分:0)
尝试
BEGIN
IF NOT EXISTS(SELECT * FROM `locality` local WHERE local.province_id=@id)
BEGIN
INSERT `locality` (province_id) values(@id)
END
END