gpt4 book ai didi

mysql - 在 INSERT INTO 问题中使用两个 SELECT FROM 语法

转载 作者:行者123 更新时间:2023-11-29 15:31:08 25 4
gpt4 key购买 nike

我有一个名为 ps_manufacturer_lang 的表,其中有 4 列,分别名为 id_manufacturerid_lang 以及 description简短描述

  1. id_manufacturer 应为 SELECT id_manufacturer FROM ps_manufacturer 中的值。

  2. id_lang 应为 1

  3. description 应为 SELECT description FROM prestashop_old.ps_category_lang WHERE id_lang='1' AND id_category IN (
    从 prestashop_old.ps_category 中选择 id_category,其中 id_parent='241')

  4. 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

似乎不可能在一个 INSERT INTO 中使用两个 SELECT FROM 语法。

有什么帮助吗?

谢谢

最佳答案

嗯。 。 。我怀疑你想要这样的逻辑。

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,看看它是否返回您想要的内容。

关于mysql - 在 INSERT INTO 问题中使用两个 SELECT FROM 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58721054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com