Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLITE - switch data in columns

Tags:

sqlite

I've got a table with the following structure:

CREATE TABLE "mytable" ("column01" INTEGER NOT NULL , "column02" INTEGER NOT NULL )

And I want to switch the values between columns - I want column02 to become column01 and column01 to become column02.

i.e.:

column01 / column02
apple / 01
day / 05
light / 28

And I want it to become:

column01 / column02
01 / apple
05 / day
28 / light

Is there a way to achieve this, using only SQL query?

Thanks.

like image 668
Ilya Suzdalnitski Avatar asked Oct 14 '25 13:10

Ilya Suzdalnitski


1 Answers

I just tested the below query and it works:

update mytable set column01 = column02, column02 = column01
like image 122
Nick Dandoulakis Avatar answered Oct 17 '25 21:10

Nick Dandoulakis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!