I have a table called ticket in which I want to swap two rows when user click up/down button from front end.
For this I added a auto-generated field called ticket_index. But I am not able to perform this action.
I wrote the following query
UPDATE ticket as ticket1
JOIN ticket as ticket2 ON (ticket1.ticket_index = 1 AND ticket2.ticket_index = 4)
OR (ticket1.ticket_index = 4 AND ticket2.ticket_index = 1)
SET
ticket1.ticket_index = ticket2.ticket_index,
ticket2.ticket_index = ticket1.ticket_index
Can anyone give me the right SQL query? Please let me know if extra information is needed for this. Thanks
use a case statement, e.g.: