Your query is valid and correct. There is also no need to put a space between the -
and the 1
.
Test case:
CREATE TABLE fly (fly_id int, fly_num int);
INSERT INTO fly VALUES (1, 1);
INSERT INTO fly VALUES (1, 2);
INSERT INTO fly VALUES (1, 3);
INSERT INTO fly VALUES (1, 4);
INSERT INTO fly VALUES (1, 5);
INSERT INTO fly VALUES (1, 6);
INSERT INTO fly VALUES (1, 7);
Update Query:
UPDATE fly SET `fly_Num` = `fly_Num` -1 WHERE fly_id ='1';
Query OK, 7 rows affected (0.00 sec)
Rows matched: 7 Changed: 7 Warnings: 0
New table contents:
SELECT * FROM fly;
+--------+---------+
| fly_id | fly_num |
+--------+---------+
| 1 | 0 |
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 1 | 5 |
| 1 | 6 |
+--------+---------+
7 rows in set (0.00 sec)
It works even if you use a varchar
for the fly_num
column:
CREATE TABLE fly (fly_id int, fly_num varchar(10));
INSERT INTO fly VALUES (1, '1');
INSERT INTO fly VALUES (1, '2');
INSERT INTO fly VALUES (1, '3');
INSERT INTO fly VALUES (1, '4');
INSERT INTO fly VALUES (1, '5');
INSERT INTO fly VALUES (1, '6');
INSERT INTO fly VALUES (1, '7');
Update Query:
UPDATE fly SET `fly_Num` = `fly_Num` -1 WHERE fly_id ='1';
Query OK, 7 rows affected (0.00 sec)
Rows matched: 7 Changed: 7 Warnings: 0
New table contents:
SELECT * FROM fly;
+--------+---------+
| fly_id | fly_num |
+--------+---------+
| 1 | 0 |
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 1 | 5 |
| 1 | 6 |
+--------+---------+
7 rows in set (0.00 sec)