How To Swap Column Values Of 2 Rows In MySQL

Setting the sort order between 2 rows in MySQL can be done in 1 line by making use of the IF() function.

I had a scenario where I had move up and move down functionalities to set the order of my database entries.

Let us say, you have columns ID and SORT_ORDER.

This line of code should do the trick.

Related Posts Plugin for WordPress, Blogger...