簡體   English   中英

將數據插入到我用來創建聯接表的表中時,更新聯接表的值

[英]update the values of joined table when insert data into tables that i used to create the joined table

我在MySQL工作台中創建了兩個表employee_tabdevices_tab

Devices_tab

Serial_No   Device_ID   Device_Name           Level
1            2001       Desktop Computer         1
2            2001       Laptop                   2
3            2001       Desktop Computer         3

employee_tab

Employee_ID Employee_Name   Designation          Password         Level

1001        Nimal           Manager             698d51a19d8a1211    1
1002        Kamal           Accountant          2c0343a2395834dd    2
1003        Sunil           Trainee             f762a2aaa148d556bd  3

現在,我需要根據每個員工的水平獲取所有設備,並創建一個新表。 同樣,在每次將新用戶插入到employee表中時,都應使用該值來更新新表。 我怎么做? 我使用SQL連接。 但是我不能每次使用舊表更新新表

 INSERT INTO table3(Device_Name,Employee_Name,Level) SELECT t1.Device_Name,t2.Employee_Name,t2.Level FROM Devices_tab t1 LEFT JOIN employees_tab t2 ON t1.Level=t2.Level 

嘗試使用此代碼。不確定,但您嘗試給出一個想法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM