![](/img/trans.png)
[英]Join one row from a table with multiple rows of two other tables in MySQL using Codeigniter
[英]MySQL Inner Join two tables and insert row from one table to other on matching row field
所以,我必须建立一个查询中添加一个新行customer_entity_varchar
每个entity_id
从包含数据customer_address_entity_varchar
表。
表结构是这样的:
+----------+----------------+--------------+-----------+---------+
| value_id | entity_type_id | attribute_id | entity_id | value |
+----------+----------------+--------------+-----------+---------+
| 132 | 1 | 5 | 12 | John |
| 133 | 1 | 7 | 12 | Doe |
| 134 | 1 | 241 | 12 | 8675309 |
+----------+----------------+--------------+-----------+---------+
value_id
是表自动生成的。
entity_type_id
将始终为1(varchar)。
attribute_id
应该设置为315。
entity_id
将在表之间匹配。
customer_address_entity_varchar
.value的值,其中customer_address_entity_varchar.attribute_id = 24
应该作为新行写入到customer_entity_varchar
。
让我知道您是否需要更多信息。
这是尝试在INSERT查询解决方案上使用的SQL小提琴:
在对其进行了进一步的研究和测试之后,我一直在寻找的答案是:
INSERT INTO customer_entity_varchar
(`entity_type_id`, `attribute_id`, `entity_id`, `value`)
SELECT 1 AS `entity_type_id`, 315 AS `attribute_id`, `entity_id`, `value`
FROM customer_address_entity_varchar WHERE `attribute_id` = 24
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.