从表a和表b中插入到表中。

时间:2022-05-01 01:55:14

I want to insert data into a table by joining two tables with a where condition that each id matches.

我希望将数据插入到一个表中,并加入两个表,其中的条件是每个id匹配。

INSERT INTO SALES(T_ID, SF)
SELECT B.T_ID, B.SF
FROM HIS B, SALES C
WHERE C.REP_ID=B.REP_ID;

I am getting an error that I cannot insert NULL into ("c.REP_ID")

我有一个错误,我不能将NULL插入("c.REP_ID")

I am not trying to insert anything into c.rep_id. I want to insert values into t_id, sf from HIS table where the rep_id on his table = rep id on sales table.

我没有尝试将任何东西插入到c.rep_id中。我想将值插入到t_id中,从他的表中,在他的表上的rep_id在sales表上为rep id。

2 个解决方案

#1


0  

INSERT INTO SALES (T_ID, SF)
SELECT h.T_ID, h.SF FROM HIS h, SALES C
WHERE C.REP_ID=B.REP_ID;

Note: Make sure that the data comes from select tables is equally compare and valid with the datatypes of the columns where you inserting.

注意:确保数据来自select表,与插入的列的数据类型相同。

#2


0  

The error simply means that the column REP_ID in the SALES table has a NOT NULL constraint. Your INSERT statement doesn't insert any value into that column (you only insert T_ID and SF) and presumably there are no before-row triggers that will set that column for you.

这个错误仅仅意味着SALES表中的列REP_ID有一个NOT NULL约束。INSERT语句没有将任何值插入到该列中(只插入T_ID和SF),并且假定没有前行触发器将为您设置该列。

#1


0  

INSERT INTO SALES (T_ID, SF)
SELECT h.T_ID, h.SF FROM HIS h, SALES C
WHERE C.REP_ID=B.REP_ID;

Note: Make sure that the data comes from select tables is equally compare and valid with the datatypes of the columns where you inserting.

注意:确保数据来自select表,与插入的列的数据类型相同。

#2


0  

The error simply means that the column REP_ID in the SALES table has a NOT NULL constraint. Your INSERT statement doesn't insert any value into that column (you only insert T_ID and SF) and presumably there are no before-row triggers that will set that column for you.

这个错误仅仅意味着SALES表中的列REP_ID有一个NOT NULL约束。INSERT语句没有将任何值插入到该列中(只插入T_ID和SF),并且假定没有前行触发器将为您设置该列。