所以这里是我需要运行的完美工作查询,但缺少必要的条件:
INSERT INTO content (`id`,`id_pages`,`content`, `date`)
SELECT `id`, `id`, `content`, `date_modified` FROM `pages`;
不幸的是,并非所有数据库都已正确同步,因此部分表格已填充,而某些表格则未填充。
我如何从表A到表B的INSERT
数据IF
表A是空的?
我尝试了几个问题:
IF (
SELECT count(id) FROM content='0',
INTO content (`id`,`id_pages`,`content`, `date`)
SELECT `id`, `id`, `content`, `date_modified` FROM `pages`)
......以及:
IF (SELECT count(id) FROM content)=0
THEN (INSERT INTO content (`id`,`id_pages`,`content`, `date`)
SELECT `id`, `id`, `content`, `date_modified` FROM `pages`);
答案 0 :(得分:1)
试试这个:
INSERT INTO content (`id`,`id_pages`,`content`, `date`)
SELECT `id`, `id`, `content`, `date_modified`
FROM `pages`
WHERE NOT EXISTS (SELECT 1 FROM content)
上述SELECT
语句的INSERT
将返回所有pages
条记录,除非至少记录在content
表中。< / p>