Julius Posted January 16, 2012 Share Posted January 16, 2012 Hello, I have this table `forums`, in it: forum_id, forum_name, forum_position. SELECT * FROM `forums` 1 Test 1 2 Test_two 2 Now, how can I swap those position numbers? I want 'Test' position to be 2 and 'Test_two' position to be 1. I tried this: UPDATE forums SET forum_position=forum_position-1, forum_position = forum_position+1 WHERE forum_id = 2 AND forum_id = 1 but it didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/255136-mysql-swap/ Share on other sites More sharing options...
Julius Posted January 16, 2012 Author Share Posted January 16, 2012 Looks like I found solution. UPDATE forums as f_one, forums as f_two set f_one.forum_position=f_two.forum_position, f_two.forum_position=f_one.forum_position where f_one.forum_id=1 AND f_two.forum_id=2 Quote Link to comment https://forums.phpfreaks.com/topic/255136-mysql-swap/#findComment-1308154 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.