Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rows matched: 1 Changed: 0 Warnings: 0 Mysql update not happening

Tags:

sql

mysql

dml

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?

like image 375
stallion Avatar asked Nov 16 '25 16:11

stallion


2 Answers

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;
like image 146
Juan Carlos Oropeza Avatar answered Nov 19 '25 06:11

Juan Carlos Oropeza


You can try below -

update userdailycalorie  
set calories_consumed= 205.4, balanced_diet =1
WHERE user_id = 3;
like image 45
Fahmi Avatar answered Nov 19 '25 05:11

Fahmi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!