user1002358 user1002358 - 1 year ago 193
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 Source

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

update your_table
set B = A
where B is null
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download