有人可以帮助我使用连接查询从3个不同的表中提取数据,这些表在每个表之间有共同的列。查询如下:
Query1 = Select * from abc.table1 -- The following are the columns: ID, CODE, DATE, SESSIONTIME.
Query2 = Select * from abc.table3 -- The following are the columns: CODE, Name, BATCH.
Query3 = Select * from abc.table2 -- The following are the columns: BATCH, TITLE
我希望显示加入查询:CODE
,DATE
,SESSIONTIME
,BATCH
,TITLE
。
DBMS是Microsoft SQL Server
答案 0 :(得分:0)
select t1.code, t1.date, t1.sessiontime, t2.batch, t3.title
from abc.table1 t1 (nolock)
left outer join abc.table2 t2 (nolock) on t1.code=t2.code
left outer join abc.table3 t3 (nolock) on t2.batch=t3.batch