我在MySQL有三個表從另一個表插入方式:wp_usermeta,directory_department和directory_departmentmemebershipSQL通過參考表
Directory_departmentmembership
| employee_id|department_id|
|:-----------|------------:|
| 1 | 2 |
| 2 | 1 |
| 3 | 3 |
directory_department
| department_id|department_name|
|:----------- |--------------:|
| 1 | Deans |
| 2 | MBA |
| 3 | Fiance |
wp_usermeta有:
| employee_id| meta_key | meta_value |
|:-----------|--------------:|:------------:|
| 1 |department_id | 2 |
| 2 |department_id | 1 |
| 3 |department_id | 3 |
| 1 |department_name| |
| 2 |department_name| |
| 3 |department_name| |
我該如何引用directory_department,以便根據meta_value字段中的department_id值插入正確的department_name?
只需使用語句:'INSERT INTO ... SELECT ... FROM ...':HTTPS://dev.mysql。 com/doc/refman/5.5/en/insert-select.html還是要求完整的INSERT和SELECT查詢? – feeela