I have a music streaming application where I have playlists. Each playlist has maximum 100 songs. I have a mapping table called PlaylistSongMapping which has the following schema
+------+------------+--------+
|SongId| PlaylistId |Position|
+------+------------+--------+
| 1 | 10 | 2 |
| 2 | 10 | 1 |
| 3 | 10 | 3 |
| 5 | 10 | 4 |
| 6 | 11 | 1 |
+------+------------+--------+
The position of each song inside playlist is managed using the Position column. Inside the playlist I need the order change functionality. The current logic is to update Position column. The problem is if i need to move the song with SongId: 3 to first position I need to update rows of SongId 1,2,3. This number would be a big one when playlist has more number of songs. Is there a better logic so that number of update queries are very minimum.