I am updating a table from mysql command line.. update is not happening..
The table description is as follows:
mysql> describe userdailycalorie;
+-------------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+----------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| balanced_diet | bit(1) | YES | | NULL | |
| calories_consumed | double | YES | | NULL | |
| date | datetime | YES | | NULL | |
| user_id | int(11) | YES | MUL | NULL | |
+-------------------+----------+------+-----+---------+-------+
5 rows in set (0.13 sec)
Corresponding table contents are as follows:
mysql> select * from userdailycalorie;
+----+---------------+-------------------+---------------------+---------+
| id | balanced_diet | calories_consumed | date | user_id |
+----+---------------+-------------------+---------------------+---------+
| 16 | | 0 | 2018-02-02 00:00:00 | 3 |
+----+---------------+-------------------+---------------------+---------+
1 row in set (0.00 sec)
Corresponding Update statement is as follows:
mysql> update userdailycalorie set calories_consumed= 205.4 and balanced_diet =true WHERE user_id = 3;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
Rows matched is 1 which indicates it picked the row.. update is not happening as changed : 0.. I am not sure why,... can anyone help me debug this issue?
If you want update two field cant use AND, separate each field to be updated with coma ,
update userdailycalorie
set calories_consumed = 205.4
, balanced_diet = true
WHERE user_id = 3;
You can try below -
update userdailycalorie
set calories_consumed= 205.4, balanced_diet =1
WHERE user_id = 3;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With