((我的英语不好,很抱歉)我想将两个不同的表插入一个。The tables I want to insert
我已经尝试了所有不同的方式。
INSERT INTO com_short
(category_id, media_folder_id, gallery_folder_id, status, important,
bgPositioning, published_at, published_by, created_at, modified_at,title,
slug, body, featured_image_file_id)
SELECT (SELECT com_post.id, category_id, media_folder_id, gallery_folder_id,
status, important, bgPositioning, published_at, published_by,
com_post.created_at, com_post.modified_at
FROM com_post
INNER JOIN com_post_translation ON com_post.id = com_post_translation.post_id
WHERE com_post_translation.post_id = com_post.id
),
(SELECT title, slug, body,featured_image_file_id
FROM com_post_translation
WHERE com_post.id = com_post_translation.post_id
);
但显示错误:The error
错误原因:您不能在子查询中选择多个列:
SELECT (SELECT com_post.id, category_id, media_folder_id, gallery_folder_id,
status, important, bgPositioning, published_at, published_by,
com_post.created_at, com_post.modified_at
FROM com_post
INNER JOIN com_post_translation ON com_post.id = com_post_translation.post_id
WHERE com_post_translation.post_id = com_post.id
),
(SELECT title, slug, body,featured_image_file_id
FROM com_post_translation
WHERE com_post.id = com_post_translation.post_id
);
简单说明:
这将产生错误:
select (select '1', '2');
这不会:
select (select '1');
将是什么[[无错误的方法] ::INSERT INTO com_short (category_id --1
, media_folder_id --2
, gallery_folder_id --3
, status --4
, important --5
, bgPositioning --6
, published_at --7
, published_by --8
, created_at --9
, modified_at --10
, title --11
, slug --12
, body --13
, featured_image_file_id) --14
SELECT cpt.category_id --1
, cpt.media_folder_id --2
, cpt.gallery_folder_id --3
, cpt.status --4
, cpt.important --5
, cpt.bgPositioning --6
, cpt.published_at --7
, cpt.published_by --8
, com_post.created_at --9
, com_post.modified_at --10
, cpt.title --11
, cpt.slug --12
, cpt.body --13
, cpt.featured_image_file_id --14
FROM com_post
INNER JOIN com_post_translation cpt ON com_post.id = cpt .post_id
:这只是一个例子,从您的问题中我无法确定您想要做什么。...注
其他信息
: