繁体   English   中英

如果条件插入

[英]Insert with if condition

我需要创建一个执行此工作的sql语句:假设我有两个包含整数字段的表A和B。 我要实现的是:

if (!(C is contained into A)) insert C into B

我正在使用SQLite。 感谢帮助

实际上,在您的特定情况下,它可能就像

 insert into B (c_value) select c_value from A where c_value = @your_c_value_here 

查看INSERT语句


抱歉,我没有注意到您的问题中对C的否定,我有另一种选择

with temp_val as (select @your_val_goes_here as val)
insert into b 
select val from temp_val where not exists
(select 1 from a where c = val)

看看这个小提琴

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM