我试图将Right join的结果插入我创建的表deal_classification_DM的CATO_NAME列中。 select的结果是我期望的,程序运行正常,但数据没有更新到表中。 怎么了?
`INSERT INTO deal_classification_DM
(CATO_NAME)
SELECT
taxonomies.NAME
FROM
taxonomies
RIGHT JOIN
deal_classification_DM ON taxonomies.ID = deal_classification_DM.CATO_ID;
插入是在我创建的表deal_classification_DM中完成的:
CREATE TABLE deal_classification_DM
AS SELECT
deal_taxonomy.DEAL_ID
,deal_taxonomy.TAXONOMY_ID AS TAXO_ID
,taxonomies.NAME AS TAXO_NAME
,taxonomies.PARENT_ID AS CATO_ID
FROM
deal_taxonomy
LEFT JOIN
taxonomies ON deal_taxonomy.TAXONOMY_ID = taxonomies.ID;
ALTER TABLE deal_classification_DM
ADD COLUMN
CATO_NAME TEXT;
答案 0 :(得分:0)
您真正需要做的是insert
而不是UPDATE deal_classification_DM d
SET d.CATO_NAME = (
SELECT name FROM taxonomies WHERE ID = d.CATO_ID
);
,例如:
INSERT
null
语句将在DEAL_ID
,TAXO_ID
和CATO_ID
列中插入包含CATO_NAME
值的新行,而您只需要更新{{{ 1}}列,因为它是一个新列。