0

I have a table ps_feature with:

-------------
|id_feature |
-------------
|1          |
|2          |
|3          |
|4          |
|5          |
|6          |
-------------

and a table ps_feature_lang with:

--------------------------------
|id_feature | id_lang  | name  |
--------------------------------
|1          | 1        | text1 |
|2          | 1        | text2 |
|4          | 1        | text3 |
|5          | 1        | text4 |
--------------------------------

Is there a MySQL script to run in PhPMyAdmin to compare two tables and add missing values in ps_feature_lang ?

The result should be:

--------------------------------
|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   |
--------------------------------

Thanks.

Mirco
  • 21
  • 5
  • Possible duplicate of [SQL - find records from one table which don't exist in another](http://stackoverflow.com/questions/367863/sql-find-records-from-one-table-which-dont-exist-in-another) – Shadow Apr 03 '17 at 11:49

1 Answers1

1

To complete a single language, you can use a left join

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
Stefano Zanini
  • 5,876
  • 2
  • 13
  • 33
  • Glad it helped! If this or any answer has solved your question please consider [accepting it](http://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Stefano Zanini Apr 03 '17 at 12:24