在INSERT INTO问题中使用两种SELECT FROM语法 [英] Using two SELECT FROM syntaxes inside INSERT INTO problem

查看:44
本文介绍了在INSERT INTO问题中使用两种SELECT FROM语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 ps_manufacturer_lang 的表,其中有4列名为 id_manufacturer id_lang description 的列short_description .

I have a table named ps_manufacturer_lang with 4 columns named id_manufacturer and id_lang and description and short_description.

  1. id_manufacturer 应该是来自 SELECT ps_manufacturer 的id_manufacturer的值.

  1. id_manufacturer should be values from 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(从prestashop_old.ps_category中选择id_category,在哪里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

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

It seems it's not possible to use two SELECT FROM syntax inside one INSERT INTO.

有什么帮助吗?

谢谢

推荐答案

Hmmm...我怀疑您想要这样的逻辑.

Hmmm . . . I suspect you want logic like this.

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

Test the select first to see if it returns what you want.

这篇关于在INSERT INTO问题中使用两种SELECT FROM语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆