如何在有条件的两个表中插入数据 [英] How insert data in two table with a condition
本文介绍了如何在有条件的两个表中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助!
我想在table3中写一个条件从table1到table2的插入语句.我的意思是,如果table3上有数据,则将数据从table2插入到table1.
我怎么能找到它?
plz help!
i want write an insert statement from data of table1 to table2 with a condition in table3.i mean if there is a data on table3 insert data from table2 to table1.
how i can wite it?
推荐答案
if exists(select * from table3 where id=4)
begin
INSERT INTO table2(field1, field2)
SELECT field1, field2
FROM table1
end
INSERT INTO @Table1 (ID)
(SELECT B.id from @Table2 A, @Table3 B where A.ID=B.ID)
您也可以使用任何联接来开发结果集&在您选择的查询上使用它
You may also use any joins to develop your result set & use it on your select query
这篇关于如何在有条件的两个表中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文