未來您可以通過使用ROW_NUMBER
產生柱連接兩張表做。看看這個例子和輸出
DECLARE @T1 TABLE (column1 INT ,column2 VARCHAR(2))
DECLARE @T2 TABLE (column1 VARCHAR(2))
INSERT INTO @T1 (column1, column2)
VALUES (0, 'A'), (1, 'B'), (2, 'C')
INSERT INTO @T2 (column1)
VALUES ('D'),('F'),('G')
SELECT *, ROW_NUMBER() OVER (PARTITION BY 1 ORDER BY (SELECT NULL)) AS RN FROM @T1
SELECT *, ROW_NUMBER() OVER (PARTITION BY 1 ORDER BY (SELECT NULL)) AS RN FROM @T2
;WITH CTE_1 AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY 1 ORDER BY (SELECT NULL)) AS RN FROM @T1)
,cte_2 AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY 1 ORDER BY (SELECT NULL)) AS RN FROM @T2)
UPDATE t1
SET t1.column2 = t2.column1
FROM CTE_1 t1
JOIN cte_2 t2
ON t1.rn = t2.rn
SELECT *, ROW_NUMBER() OVER (PARTITION BY 1 ORDER BY (SELECT NULL)) AS RN FROM @T1
SELECT *, ROW_NUMBER() OVER (PARTITION BY 1 ORDER BY (SELECT NULL)) AS RN FROM @T2
這是MySql還是SQL Server?答案取決於你正在使用哪一個。 –
@MauriceReeves sql服務器管理工作室 –
所以你沒有匹配的列,但你想使用內部連接。首先告訴我們爲什麼你想更新沒有邏輯? – Imran