mysql - 在 INSERT INTO 问题中使用两个 SELECT FROM 语法
问题描述
我有一个名为ps_manufacturer_lang
4 列的表,名为id_manufacturer
andid_lang
和description
and short_description
。
id_manufacturer
应该是来自 的值SELECT id_manufacturer FROM ps_manufacturer
。id_lang
应该是1
。description
应该是来自的值SELECT description FROM prestashop_old.ps_category_lang WHERE id_lang='1' AND id_category IN ( SELECT id_category FROM prestashop_old.ps_category WHERE id_parent='241')
short_description
应该是NULL
。
这是我的代码:
INSERT INTO ps_manufacturer_lang (id_manufacturer, id_lang, description, short_description)
SELECT
id_manufacturer
FROM ps_manufacturer
1,
SELECT
description
FROM prestashop_old.ps_category_lang
WHERE
id_lang='1'
AND id_category IN (
SELECT id_category FROM prestashop_old.ps_category WHERE id_parent='241'
)
NULL
错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1,
SELECT
description
FROM prestashop_old.ps_category_lang
WHERE
' at line 5
似乎不可能SELECT FROM
在一个中使用两种语法INSERT INTO
。
有什么帮助吗?
谢谢,
解决方案
嗯。. . 我怀疑你想要这样的逻辑。
INSERT INTO ps_manufacturer_lang (id_manufacturer, id_lang, description, short_description)
SELECT m.id_manufacturer, 1, cl.description, NULL
FROM ps_manufacturer m join
prestashop_old.ps_category_lang cl
ON cl.id_lang = 1 and
cl.id_category IN (
SELECT id_category
FROM prestashop_old.ps_category
WHERE id_parent = 241
);
测试第select
一个,看看它是否返回你想要的。
推荐阅读
- angular - 404 page not found error while publishing Angular project on Github pages
- python-3.x - 如何创建一个 PyTables 表来存储一个巨大的方阵?
- java - 我如何在java中结束这个游戏?
- javascript - 有人可以给我简单的术语来说明如何将 Meteor 应用程序上传到 Galaxy 吗?
- c++ - 类的方法内部循环没有运行?
- javascript - chrome 扩展在 facebook 上无法正常工作
- python - 为什么代码没有通过单元测试?
- reactjs - 如何在 Typescript 中使用带有按钮的 Material UI Styled 和 System API?
- javascript - 将 kotlin 程序放在网站上的最佳方法是什么?
- flask - 从 Microsoft Power BI 到烧瓶 Web 应用程序