Invert 0 or 1 in a column

Asked

Viewed 164 times

4

I have a table that has numerous records and a column called posição.

It only gets the value 0 for locked and 1 for released.

There now with a change I need to reverse these values, where this 0 has to be 1 and where this 1 has to be 0.

How do I do it in update mysql?

1 answer

5


  • So I don’t know how to do this update. The table is called Orders and the column in question is called position as I said above. In this column only accept 0 and 1 in the values I need to run an update that reverses them. Where position=1 has to be position=0 and where position=0 has to be position=1. I hope I’ve been able to explain better.

  • @But Joaonivaldo is exactly what is in the answer, no?

  • 1

    @Joaonivaldo, the answer is correct. When posicao is equal to 0, the update will do the account 1 - 0 which is equal to 1 (reversed from 0 to 1). If posicao is equal to 1, the update will do the account 1 - 1 equal to 0 (reversed from 1 to 0).

  • It was perfect. It is that the first time I saw it was written table where appeared position so I did not understand. Ai after I had responded appeared to your edition. Thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.