SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
drop table demo; create table t1(id int, text1 text); create table t2(id int, text1 text); insert into t1 values (1, 'Шла'), (2, null) ,(3, 'По'), (4, null), (5, 'И'), (6, null), (7, null); insert into t2 values (1, 'Саша'), (2, 'Шоссе') ,(3, null), (4, null), (5, 'Сосала'), (6, 'Сушку'), (7, null); select row_number() over (order by id) num1, id, text1 from t1 where text1 is null ; SELECT row_number() over (order by id) num2, id, text1 from t2 where text1 is not null ; WITH a1 AS ( select row_number() over (order by id) num1, id, text1 from t1 where text1 is null ), a2 as ( SELECT row_number() over (order by id) num2, id, text1 from t2 where text1 is not null ) UPDATE t1 set text1= ( SELECT a2.text1 FROM a1 JOIN a2 ON a2.num2=a1.num1 where a1.id = t1.id ) where text1 is null; select * from t1 order by id;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear