如何将新记录从一个 table 插入另一个 table
How to insert new records from one table into another table
我想将出现在 tbl_Daily
中的任何新记录插入到我的 tbl_Cumulative
中。我的 tbl_Cumulative
综合了所有历史 tbl_Daily
记录。 tbl_Daily
每天刷新
我的 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
我首先加入基于 ID
的表并且没有与 tbl_Cumulative
匹配的表(也就是新记录),然后将其附加到 tbl_Cumulative
。
但是,我最终收到以下错误:
Duplicate output destination 'ID'.
我知道 ID
有重复字段,因为 tbl_Cumulative
和 tbl_Daily
具有完全相同的列。我如何查询我的 SQL 以便我仍然可以匹配新查询并将它们附加到 tbl_Cumulative
?
SELECT
仅来自一个 table (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
我想将出现在 tbl_Daily
中的任何新记录插入到我的 tbl_Cumulative
中。我的 tbl_Cumulative
综合了所有历史 tbl_Daily
记录。 tbl_Daily
每天刷新
我的 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
我首先加入基于 ID
的表并且没有与 tbl_Cumulative
匹配的表(也就是新记录),然后将其附加到 tbl_Cumulative
。
但是,我最终收到以下错误:
Duplicate output destination 'ID'.
我知道 ID
有重复字段,因为 tbl_Cumulative
和 tbl_Daily
具有完全相同的列。我如何查询我的 SQL 以便我仍然可以匹配新查询并将它们附加到 tbl_Cumulative
?
SELECT
仅来自一个 table (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