sql - 如果该列中不存在列值,则插入列值
答案 0 :(得分:16)
嗯。你想要一个新行吗?在那种情况下,
IF NOT EXISTS(SELECT 1 FROM emp WHERE fruits = 'mango')
INSERT INTO emp (fruits) VALUES ('mango')
答案 1 :(得分:5)
两种方法
1.IF NOT EXISTS (SELECT fruit FROM emp WHERE fruit='mango')
BEGIN
INSERT INTO emp(fruit) Values('mango');
END
2.INSERT INTO emp ('mango') SELECT distinct fruit FROM emp WHERE not exists (select fruit from emp as e Where emp.fruit = e.fruit);