![](/img/trans.png)
[英]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.