user1002358 user1002358 - 1 month ago 12
MySQL Question

SQL set values of one column equal to values of another column in the same table

I have a table with two DATETIME columns.

One of them is never NULL, but one of them is sometimes NULL.

I need to write a query which will set all the NULL rows for column B equal to the values in column A.

I have tried this example but the SQL in the selected answer does not execute because MySQL Workbench doesn't seem to like the FROM in the UPDATE.

Answer

Sounds like you're working in just one table so something like this:

update your_table
set B = A
where B is null
Comments