I want to insert into my tbl_Cumulative
any new records that appear in tbl_Daily
. My tbl_Cumulative
is comprehensive of all historical tbl_Daily
records. tbl_Daily
is refreshed every day.
我想在tbl_Daily中插入出现在tbl_Cumulative中的所有新记录。我的tbl_Cumulative是所有历史tbl_Daily记录的综合。 tbl_Daily每天都会刷新。
My INSERT INTO
statement looks like below:
我的INSERT INTO语句如下所示:
INSERT INTO tbl_Cumulative
SELECT *
FROM tbl_Daily
LEFT JOIN tbl_Cumulative
ON tbl_Cumulative.ID= tbl_Daily.ID
WHERE tbl_Cumulative.ID IS NULL
I first join the tables based on ID
and where there is no match with tbl_Cumulative
(aka a record is new), then append it to tbl_Cumulative
. However, I end up getting the below error:
我首先根据ID加入表,并且与tbl_Cumulative(也就是记录是新的)不匹配,然后将其附加到tbl_Cumulative。但是,我最终得到以下错误:
Duplicate output destination 'ID'.
重复输出目标“ID”。
I know there is duplicate fields for ID
because tbl_Cumulative
and tbl_Daily
have the exact same columns. How could I query my SQL so that I can still match new queries and append them to tbl_Cumulative
?
我知道ID有重复的字段,因为tbl_Cumulative和tbl_Daily具有完全相同的列。我怎么能查询我的SQL,以便我仍然可以匹配新的查询并将它们附加到tbl_Cumulative?
1 个解决方案
#1
1
SELECT
the fields from only one table (tbl_Daily.*
) instead of all the fields returned in the SELECT *
result set.
仅从一个表(tbl_Daily。*)中选择字段,而不是SELECT *结果集中返回的所有字段。
INSERT INTO tbl_Cumulative
SELECT tbl_Daily.*
FROM tbl_Daily
LEFT JOIN tbl_Cumulative
ON tbl_Cumulative.ID= tbl_Daily.ID
WHERE tbl_Cumulative.ID IS NULL
#1
1
SELECT
the fields from only one table (tbl_Daily.*
) instead of all the fields returned in the SELECT *
result set.
仅从一个表(tbl_Daily。*)中选择字段,而不是SELECT *结果集中返回的所有字段。
INSERT INTO tbl_Cumulative
SELECT tbl_Daily.*
FROM tbl_Daily
LEFT JOIN tbl_Cumulative
ON tbl_Cumulative.ID= tbl_Daily.ID
WHERE tbl_Cumulative.ID IS NULL