简体   繁体   English

MySQL从另一个表插入值

[英]Mysql Insert value from another table

I have two tables : table1(t1_id, t1_name) , table2(t2_id, t1_id) . 我有两个表: table1(t1_id,t1_name)table2(t2_id,t1_id)

now if i try to insert value into table2 like this: 现在,如果我尝试像这样将值插入到table2中:

INSERT INTO table2(t2_id, t1_id) values(110202,(SELECT t1_id FROM table1));

This create an error : "subquery returns more than 1 row", which means it can insert only one row. 这将产生错误:“子查询返回多于1行”,这意味着它只能插入一行。 But i want to insert all cartesian product. 但是我想插入所有笛卡尔积。

May be you are looking for this 可能是您在寻找这个

INSERT INTO table2(t2_id, t1_id)

SELECT 110202,t1_id FROM table1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM