I'm using SQL Server and have Management Studio installed if this is relevant.
I would like to copy a whole column from one table to another, but the catch is that the table I must copy to needs to be ordered a certain way, as there is no common identity between these tables I could use to join them.
I have read these two questions:
and I tried to combine their answers as follows:
WITH cte AS
(
-- I must specify TOP to use ORDER BY
SELECT TOP(50000) *
FROM TableToCopyTo
ORDER BY ColumnUsedToOrder
)
UPDATE cte
SET ColumnToCopyTo = (SELECT ColumnToCopyFrom FROM TableToCopyFrom)
When I try to execute this query, it returns the following error:
Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
I've tried looking up the error but couldn't find relevant information.
I would like to either understand why my query is wrong or find an alternative to achieve what I'm looking for.