articles
,其中缺少一些数据。articles_tmp
中,我有部分缺失的数据。articles.path WHERE path IS NULL
。articles_tmp.path WHERE path IS NOT NULL
使用 SQLite ,这不起作用:
UPDATE articles
SET path = (
SELECT at.path
FROM articles_tmp AS at, articles AS a
WHERE at.article_id = a.id AND a.path IS NULL AND NOT at.path IS NULL
)
WHERE path IS NULL
使用MS Access,这很好用:
UPDATE articles
INNER JOIN articles_tmp
ON articles.id = articles_tmp.id
SET articles.path = articles_tmp.path
WHERE articles.path IS NULL AND articles_tmp.path IS NOT NULL
有人可以帮忙吗?
答案 0 :(得分:1)
由于我提供的SQL Server语法不起作用,这是我提出的解决方案。只需稍微修改一下您的原始查询,但使用我的"关联"建议补充说。这是一个SQL小提琴:http://sqlfiddle.com/#!7/34589/7
以下是代码:
UPDATE articles
SET path = (SELECT path FROM articles_tmp AS t WHERE t.id = articles.id)
WHERE path IS NULL;
答案 1 :(得分:0)
有效(非常相关,可能太多):
UPDATE articles
SET path = (
SELECT at.path
FROM articles_tmp AS at
WHERE at.article_id=articles.id
)
WHERE EXISTS (
SELECT *
FROM articles_tmp AS at
WHERE at.article_id=articles.id AND articles.path IS NULL AND NOT at.path=''
)