I’m trying to clear one column for all records in my table.
For example, if my table had three columns: id, comment, and likes – I would like to be able to clear the likes column.
+---+-------+-----+
|id |comment|likes|
+-----------------+
|1 |hi |3 |
|2 |hello |12 |
|3 |hey |1 |
+---+-------+-----+
so that afterwards it would look like this:
+---+-------+-----+
|id |comment|likes|
+-----------------+
|1 |hi | |
|2 |hello | |
|3 |hey | |
+---+-------+-----+
I’m guessing I would have to use MySQL UPDATE to clear the likes value, but how do I iterate through all records and keep the id and comment fields the same?
I don’t want to change each record manually.
or if your
likescolumn does not allowNULL:Some SQL tools that are used for executing DB queries prevent updates on ALL records (queries without a
whereclause) by default. You can configure that and remove that savety setting or you can add awhereclause that istruefor all records and update all anyway like this:If you compare with
NULLthen you also need theISoperator. Example:because comparing
NULLwith the equal operator (=) returns UNKNOWN. But theISoperator can handleNULL.