 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 
-select distinct emi_id, 'emanimi',   SUBSTRING_INDEX(SUBSTRING_INDEX(replace(replace(emanimi, '-',';'),' ',';'), ';', n.n), ';', -1)
-from kirjed k 
-INNER JOIN
-(select 1 n union all
- select 2   union all select 3 union all
- select 4   union all select 5 union all
- select 6   union all select 7 union all
- select 8   union all select 7 union all
- select 10  union all select 11) n
-where k.emanimi != '' ;
-
-
+TRUNCATE TABLE x_nimekujud4;
 
 insert ignore into x_nimekujud4 (id, tunnus, v)
-select emi_id, 'perenimi',  SUBSTRING_INDEX(SUBSTRING_INDEX(replace(replace(perenimi,'-',';'),' ',';'), ';', n.n), ';', -1)
+select distinct emi_id, 'perenimi',  SUBSTRING_INDEX(SUBSTRING_INDEX(replace(replace(perenimi,'-',';'),' ',';'), ';', n.n), ';', -1)
 from kirjed k 
 INNER JOIN
 (select 1 n union all select 2 union all select 3 union all select 4 union all 

where eesnimi != '' ;

insert ignore into x_nimekujud4 (id, tunnus, v)
select emi_id, 'isanimi',   SUBSTRING_INDEX(SUBSTRING_INDEX(replace(replace(isanimi, '-',';'),' ',';'), ';', n.n), ';', -1)
from kirjed k 
INNER JOIN
(select 1 n union all select 2 union all select 3 union all select 4 union all 

where sünd != '' ;

insert ignore into x_nimekujud4 (id, tunnus, v)
select distinct emi_id, 'surm', left(SUBSTRING_INDEX(SUBSTRING_INDEX(                                      surm, ';', n.n), ';', -1), 4)
from kirjed k 
INNER JOIN
(select 1 n union all select 2 union all select 3 union all select 4 union all 
