ЕСЛИ вы не возражаете против дублирования элементов в rel1 (т. Е. Объединение дубликатов относится к столбцам att?) И ЕСЛИ Столбец att1 имеет УНИКАЛЬНОЕ ограничение, то: -
WITH a AS(SELECT att1,rel1 FROM `table1` UNION SELECT att2 AS att1,rel2 AS rel1 FROM `table-2`),
b AS (SELECT att1,group_concat(rel1) AS rel1 FROM a GROUP BY att1)
INSERT OR REPLACE INTO `table1` SELECT att1,rel1 FROM b;
приведет к
ЕСЛИ вы не возражаете против повторяющихся элементов в rel1 НО столбец att1 не имеет УНИКАЛЬНОГО ограничения, тогда: -
WITH a AS(SELECT att1,rel1 FROM `table1` UNION SELECT att2 AS att1,rel2 AS rel1 FROM `table-2`),
b AS (SELECT att1,group_concat(rel1) AS rel1 FROM a GROUP BY att1)
INSERT INTO `table1` SELECT 'ADDED-'||att1,rel1 FROM b;
DELETE FROM `table1` WHERE instr(att1,'ADDED-') < 1;
UPDATE `table1` SET att1 = substr(att1,instr(att1,'ADDED-') + 1 + length('ADDED'));
или: -
CREATE UNIQUE INDEX IF NOT EXISTS att1ix ON `table1`(att1);
WITH a AS(SELECT att1,rel1 FROM `table1` UNION SELECT att2 AS att1,rel2 AS rel1 FROM `table-2`),
b AS (SELECT att1,group_concat(rel1) AS rel1 FROM a GROUP BY att1)
INSERT OR REPLACE INTO `table1` SELECT att1,rel1 FROM b;
даст тот же результат.