Increment/Deincrment value in MySQL

时间:2015-06-30 13:39:13

标签: mysql

Table:

enter image description here

What I am trying to do is ++ or -- the ORD value by selecting the id_phonebook.

Query:

SELECT * FROM phonebook WHERE id_phonebook = '$entry_id' ALTER ORD-1 

Am I going the right way about this or do I need to make this query more sophisticated? Not much of a DB Admin.

1 个答案:

答案 0 :(得分:3)

I believe you need an UPDATE statement.

To increment:

update phonebook set ord=ord +1 where id_phonebook = '$entry_id'

To decrement:

update phonebook set ord=ord -1 where id_phonebook = '$entry_id'

Reference: