我有一个 ps_feature 表:
-------------
|id_feature |
-------------
|1 |
|2 |
|3 |
|4 |
|5 |
|6 |
-------------
和一个表 ps_feature_lang :
--------------------------------
|id_feature | id_lang | name |
--------------------------------
|1 | 1 | text1 |
|2 | 1 | text2 |
|4 | 1 | text3 |
|5 | 1 | text4 |
--------------------------------
是否有一个 MySQL 脚本可以在 PhPMyAdmin 中运行来比较两个表并在 ps_feature_lang 中添加缺失值?
结果应该是:
--------------------------------
|id_feature | id_lang | name |
--------------------------------
|1 | 1 | text1 |
|2 | 1 | text2 |
|3 | 1 | N/A |
|4 | 1 | text3 |
|5 | 1 | text4 |
|6 | 1 | N/A |
--------------------------------
谢谢。
最佳答案
要完成单一语言,您可以使用左连接
insert into ps_feature_lang
select f.id_feature, 1, 'N/A'
from ps_feature f
left join
ps_feature_lang fl
on f.id_feature = fl.id_feature and
fl.id_lang = 1
where fl.id_feature is null
关于MySQL比较两个表并添加缺失值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43182696/