php - Swap column values in MySql -


i trying swap column value, , can't figure out how done. lets have 2 rows, 1 id of 2 , id of 5. both of these rows have column called "position".

i want swap "position" row id of 2, "position" of row id of 5.

so if id-2 row's position 34 , id-5 row's position 12

id position 2    34 5    12 

the new values be:

id position 2    12 5    34 

how done?

if want in 1 go, can use simple update statement. note: if plan copy code here, copy , don't quote table or column names using single quote character (this one: ').

update `your_table`  inner join `your_table` b  on a.id = 2 , b.id = 5  set a.`position` = b.`position`, b.`position` = a.`position` 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -