[英]When inserting data in two tables in send table id is not insert but when i am inserting data second table id should inserted from first table
[英]how to insert user name from first table into second table based on userid from both tables whle inserting other values into table2
例如,我有一个users表,其中userid是PK,然后另一个表是tblmood,这里的userid是users表的PK和FK,我将在其中插入一些复选框值到tblmood中
我如何根据用户ID的匹配情况从用户表中将用户名插入tblmood中,我遇到了类似的问题,但没有正确的想法。 感谢您的任何帮助。
假设您的表如下:
tbl
id username
1 a
2 b
3 c
tblmood
id username
1 NULL
2 NULL
3 NULL
如果我了解您的要求,解决方案将是:
update tblmood tm set tm.username = t.username
where tm.id = t.id
如果上述解决方案不符合您的要求,请详细说明您的问题。 谢谢 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.