    select 5 union all select 6 union all select 7 union all select 8 union all 
    select 9 union all select 10 union all select 11 union all select 12 union all 
    select 13 union all select 14 union all select 15 union all select 16 union all select 17) n
-where allikas != 'Nimekujud' and sünd != '' ;
+where allikas != 'Nimekujud' and sünd != ''
+  and k.MR != '!';
 
 -- 8.
 insert ignore into x_nimekujud (id, tunnus, v, moonutatud)

   select 5 union all select 6 union all select 7 union all select 8 union all 
   select 9 union all select 10 union all select 11 union all select 12 union all 
   select 13 union all select 14 union all select 15 union all select 16 union all select 17) n
where allikas != 'Nimekujud' and isanimi != '' ;

-- 12.
insert ignore into x_nimekujud (id, tunnus, v, moonutatud)

-- create or replace table aruanne_kontrolli_seoseid3
-- INSERT IGNORE INTO z_queue (isikukood1, isikukood2, task) SELECT k1.isikukood, k2.isikukood, 'Remove connections'
-- INSERT IGNORE INTO z_queue (isikukood1, isikukood2, task) SELECT k1.isikukood, k2.isikukood, 'Create connections'
select concat('emi_id in (',id1,',',id2,')') as koodid
     , e1.kirjed as kirjed1
     , if(s.seos = 'erinevad isikud', 'E', 
     		if(s.seos = 'kahtlusseos', 'U', NULL)) as kasSama
     , e2.kirjed as kirjed2
from (
  select y1.id as id1, y2.id as id2 from y_nimekujud y1
  left join y_nimekujud y2 
         on y2.id < y1.id 
        and y2.perenimi = y1.perenimi 
        and y2.perenimi != ''
        and y2.eesnimi = y1.eesnimi 
        and y2.eesnimi != ''
        and y2.isanimi = y1.isanimi
        and y2.isanimi != ''
        and y2.sünd = y1.sünd 
        and y2.surm = y1.surm
        and (y1.sünd != '' or y2.surm != '')
  where y2.id is not null
  group by y1.id, y2.id
) yy
