Jim Bob
Jim Bob

Reputation: 1

How to change a record position in mysql table?

How can I change a record position in mysql table? I create a table that has about 200 records. How can I change record number 19 to 8?

Upvotes: 0

Views: 481

Answers (2)

Vijunav Vastivch
Vijunav Vastivch

Reputation: 4211

Identically you cant change it or swap but you can do it in a query as a view:

like this:

select case when id = 19 then 8 else 
 (case when id = 8 then 19 else id end) end as id from yourTable

Upvotes: 0

deviantxdes
deviantxdes

Reputation: 479

You can swap the data in the tuples with an update statement.

update table1 a
 inner join table1 b on a.id <> b.id
   set a.col1= b.col1,
       a.col2= b.col2,
       a.col3= b.col3
 where a.id in (8,19) and b.id in (8,19)

Result: row values are swapped.

Upvotes: 1

Related Questions