SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table t ( id varchar primary key, v int, d varchar ); insert into t(id, v, d) values ('a', 1, '2'),('lo', 2, '2'),('lkh', 2, '3'),('cf', 1, '2'),('jd', 1, '3'),('lk', 2,'3'),('lkhr', 2,'3'),('lkhs', 2,'4'), ('lkhds', 1,'4'), ('lkdhds', 1,'5') ,('lds', 3,'3'); -- drop table if exists t_back; -- create table t_back ( -- id varchar primary key, -- v int, -- d varchar -- ); create table t_back as select t.id, t.v, t.d from t; -- insert into t_back -- select * from t; select * from t_back; delete from t; select * from t; insert into t select * from t_back; drop table if exists t_back; select * from t; select * from t_back; -- select * from t; -- select distinct t.id -- from t left join t t1 on t.d = t1.d and t.id > t1.id and t1.v = t.v -- where -- -- t.v = 2 -- -- ; -- -- and -- t1.id is not null; -- with duplicateId as ( -- select t.id id -- from t -- left join t t1 on t.d = t1.d and t.id > t1.id and t.v = t1.v where t1.id is not null -- ) -- delete from t -- where id in ( -- duplicateId.id -- ); -- select * from t ;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear