简体   繁体   English

我将如何在内部联接中插入数据库记录

[英]How will i Insert database record in inner join

I created an Update query for two tables with INNER JOIN and its working fine. 我使用INNER JOIN为两个表创建了一个Update查询,它的工作正常。 The code is below. 代码如下。

table 1 = circuiti , table 2 = clienti 表1 = Circuiti,表2 = clienti

UPDATE circuiti INNER JOIN clienti ON circuiti.Cod = 
clienti.Cod_ SET es = ?,   
test = ?, type = ?, Note =? 
WHERE circuiti.id= ?" 

But i want to implement same as this in INSERT query like creating a new record through INNER JOINT of tables. 但是我想在INSERT查询中实现与此相同的功能,例如通过表的INNER JOINT创建新记录。 thank you. 谢谢。

MySQL does not support the insertion of data into multiple tables in a single sql command. MySQL不支持在单个sql命令中将数据插入到多个表中。 As MySQL documentation on insert statement says: 正如关于插入语句的 MySQL文档所说:

tbl_name is the table into which rows should be inserted. tbl_name是应在其中插入行的表。

You need to issue 2 insert statements after each other. 您需要互相发出2条插入语句。 If you include the 2 inserts into a single transaction, then you can commit or rollback both statements as a single unit. 如果在单个事务中包含两个插入,则可以将两个语句作为一个单元提交或回滚。

However, if you want to insert into a single table based on values from multiple tables, that can be achieved through an insert ... select ... statement, where the select part would have the join of the 2 tables. 但是,如果要基于多个表中的值插入单个表中,则可以通过insert ... select ...语句来实现,其中select部分将具有2个表的联接。

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

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