sql - query to insert a column value if it does not exist in that column
Example using VLOOKUP You can check if the values in column A exist in column B using VLOOKUP. Select cell C2 by clicking on it. Insert the formula in “=IF(ISERROR(VLOOKUP(A2,$B$2:$B$1001,1,FALSE)),FALSE,TRUE)” the formula bar. Press Enter to assign the formula to C2.
Hm. Do you want a new row? In that case,
IF NOT EXISTS(SELECT 1 FROM emp WHERE fruits = 'mango')
INSERT INTO emp (fruits) VALUES ('mango')
Two ways to do
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With