MS SQL Server。SQL在多個字段中左側連接多個表
我有10個表(table1,table2,table3等..),我想離開他們,並從每個表中獲取幾個字段。一些表格需要在多個字段上保持連接,例如, table1和table2需要在3個字段中加入。
這裏是我嘗試使用該腳本的樣本,但我得到的錯誤(我掩蓋了真正的表和字段名):
SELECT table1.[Field1],
table1.[Field2],
table1.[Field3],
table1.[Field5],
table2.[Field1],
table2.[Field2],
table2.[Field3],
table3.[Field4],
table4.[Field1],
table4.[Field4],
table4.[Field5],
table5.[Field4],
FROM table2
LEFT JOIN table1 As a
on a.[Field1] = table2.[Field1]
LEFT JOIN table1 As b
on b.[Field3] = table2.[Field3]
LEFT JOIN table1 As c
on c.[Field2] = table2.[Field2]
LEFT JOIN table4 As d
on table1.[Field5] = d.[Field4]
LEFT JOIN table4 As e
on table1.[Field1] = e.[Field1]
LEFT JOIN table5
on table4.[Field4] = table5.[Field4]
LEFT JOIN table3
on table4.[Field4] = table3.[Field4];
任何「簡單」的方法呢?
您加入tables.let我們知道你已經嘗試過什麼,你想要做什麼的簡單方法是什麼意思? –
該帖子現在被編輯。 – Jasu