UPDATE main_cats set cat_order=(
CASE
when cat_order='4' THEN (4-1)
WHEN cat_order=(4-1) THEN '4'
END)
When I run the above query on the bottom data I get.
cat_id cat_name cat_order cat_visible
0 NO MAIN CAT 0 N
5 CLOTHES 1 N
6 GIFTS 2 N
7 ARTWORK 3 Y
8 TEST CATEGO 4 N
I end up with
cat_id cat_name cat_order cat_visible
0 NO MAIN CAT 0 N
5 CLOTHES 0 N
6 GIFTS 0 N
7 ARTWORK 3 Y
8 TEST CATEGO 3 N
Not sure why the others go to ZERO in the CASE statement.
It is because you are updating the column without a where and your conditional is only setting a value in two scenarios. For the rest I would guess it assumes zero with no input. I think this could work: