I believe a subquery would do:
UPDATE IEX_Tick SET SomeColumn = (
SELECT CONCAT(
from_unixtime(lastSaleTime/1000, '%Y-%d-%m %h:%i:%s.'),
CAST(EXTRACT(MICROSECOND FROM from_unixtime(lastSaleTime/1000))/1000 AS SIGNED)
) FROM IEX_Tick;
)
Edit:
(in response to this comment)
After doing some research, I found that, even though the suggested solution above is valid SQL
, it's not a supported way of updating a table in MySQL
.
Information I gathered from various related posts here on Stack Overflow (such as this and this) suggests that MySQL
restricts these types of UPDATE
queries:
... because your update could be cyclical… what if updating that record causes something to happen which made the WHERE condition FALSE? You know that isn’t the case, but the engine doesn’t. There also could be opposing locks on the table in the operation.
Therefore, a viable alternative that helps avoid this arbitrary restriction set by MySQL
is to use another subquery, this time in your FROM
clause, as shown below:
UPDATE IEX_Tick SET SomeColumn = (
SELECT CONCAT(
from_unixtime(lastSaleTime/1000, '%Y-%d-%m %h:%i:%s.'),
CAST(EXTRACT(MICROSECOND FROM from_unixtime(lastSaleTime/1000))/1000 AS SIGNED)
) FROM (
SELECT * FROM IEX_Tick AS SomeName
);
)
Note: I would personally avoid using the SELECT * FROM IEX_Tick
, especially if IEX_Tick
has many columns. I good way to optimise the subquery would be to use only the column(s) needed.