SQLite Forum

Switching data between two columns
Login
This line 

REPLACE INTO <table> (... c3, c4, ...) SELECT ... c4, c3, ... FROM <table>;

is executable after replacing <table> with an appropriate name BUT the records are appended rather than replaced. IS REPLACE a synonym for INSERT?

Also, if you had a where clause, where would it go?

My Session:

sqlite> .mode column
sqlite> .headers on
sqlite> drop table if exists xx;
sqlite> create temp table xx (c3,c4);
sqlite> insert into xx values(1,2),(3,4);
sqlite> select * from xx;
c3  c4
--  --
1   2
3   4
sqlite> replace into xx (c4,c3) select c3,c4 from xx where c3 in(1,3);
sqlite> select * from xx;
c3  c4
--  --
1   2
3   4
2   1
4   3
sqlite>