简体   繁体   English

MySQL在一个查询中将多个表中的值插入一个表中?

[英]MySQL Insert values from multiple table in one table in one query?

I am using MySQL database. 我正在使用MySQL数据库。

Supposedly I have 3 table. 据说我有3张桌子。

Table A : column ida
Table B : column idb
Table C: column A,B

I want to write a single through which I can insert values from Table A and Table B to Table C ?? 我想写一个单一的,我可以通过它将表A和表B的值插入表C ??

It should be something like this 它应该是这样的

insert into tablec
select a.ida, b.idb
from tablea a
inner join tableb b on -- relation between tablea and tableb

but you'll have to finish inserting the relation between tables. 但你必须完成插入表之间的关系。

INSERT INTO C SELECT id1, id2 FROM A, B WHERE ...

我假设C只有两列,它们与表A和B中id1和id2的数据类型相同。我希望你能得到这个想法。

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

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