Mysql 从子查询插入
我试图根据子查询的结果进行插入,但始终出现相同的错误:Mysql 从子查询插入,mysql,magento,Mysql,Magento,我试图根据子查询的结果进行插入,但始终出现相同的错误: Operand should contain 1 column(s) 问题是: INSERT INTO customer_entity_int (attribute_id, entity_type_id, entity_id, `value`) VALUES (14, ( SELECT entity_type_id, entity_id, `value` FROM customer_entity_int WHE
Operand should contain 1 column(s)
问题是:
INSERT INTO customer_entity_int
(attribute_id, entity_type_id, entity_id, `value`)
VALUES (14, (
SELECT entity_type_id, entity_id, `value`
FROM customer_entity_int
WHERE attribute_id = 13
AND entity_id NOT
IN (
SELECT entity_id
FROM customer_entity_int
WHERE attribute_id = 14
)
))
如何为插入选择多个列?请尝试dis:
INSERT INTO customer_entity_int
(attribute_id, entity_type_id, entity_id, `value`)
SELECT 14, entity_type_id, entity_id, `value`
FROM customer_entity_int
WHERE attribute_id = 13
AND entity_id NOT
IN (
SELECT entity_id
FROM customer_entity_int
WHERE attribute_id = 14
)
试一试dis:
INSERT INTO customer_entity_int
(attribute_id, entity_type_id, entity_id, `value`)
SELECT 14, entity_type_id, entity_id, `value`
FROM customer_entity_int
WHERE attribute_id = 13
AND entity_id NOT
IN (
SELECT entity_id
FROM customer_entity_int
WHERE attribute_id = 14
)
您需要使用
插入到…从中选择,而不是插入到..值中
:
INSERT INTO customer_entity_int (attribute_id, entity_type_id, entity_id, `value`)
SELECT 14, entity_type_id, entity_id, `value`
FROM customer_entity_int
WHERE attribute_id = 13
AND entity_id NOT IN (SELECT entity_id
FROM customer_entity_int
WHERE attribute_id = 14)
您可以在选择列表中为您的属性id
添加一个静态值,您将希望使用插入到…选择从而不是插入到..值中
:
INSERT INTO customer_entity_int (attribute_id, entity_type_id, entity_id, `value`)
SELECT 14, entity_type_id, entity_id, `value`
FROM customer_entity_int
WHERE attribute_id = 13
AND entity_id NOT IN (SELECT entity_id
FROM customer_entity_int
WHERE attribute_id = 14)
您可以在属性id的选择列表中包含一个静态值。请尝试以下代码
INSERT INTO customer_entity_int
(attribute_id, entity_type_id, entity_id, `value`)
SELECT 14, entity_type_id, entity_id, `value`
FROM customer_entity_int
WHERE attribute_id = 13
AND entity_id NOT
IN (
SELECT entity_id
FROM customer_entity_int
WHERE attribute_id = 14
)
请尝试以下代码
INSERT INTO customer_entity_int
(attribute_id, entity_type_id, entity_id, `value`)
SELECT 14, entity_type_id, entity_id, `value`
FROM customer_entity_int
WHERE attribute_id = 13
AND entity_id NOT
IN (
SELECT entity_id
FROM customer_entity_int
WHERE attribute_id = 14
)
完美,这是一种享受,我会接受它让我尽快完美,这是一种享受,我会接受它让我尽快