2013-02-28 119 views
0

在SQL Server中,是否有機會顯示3個表的結果? (其實4)從3個表中獲取記錄

第4張表包含1列與其他類似。其他3個表的相似列的值是不同的。換句話說,如果您在第4列表格中選擇'1',則應該顯示第1個表格的結果,如果您選擇'2',第2個等...

+1

您可以添加一些佈局示例四張桌子? – 2013-02-28 03:36:26

+0

謝謝你的回覆。我有一個想法去做。 – 2013-02-28 03:53:16

回答

0
select fourth.pk, 
case fourth.columnx 
when '1' then one.columnx 
when '2' then two.columnx 
when '3' then three.columnx 
else 'Exception to the rule?' 
end as 'Column A' 
from fourth 
join one on fourth.joinid=one.joinid 
join two on fourth.joinid=two.joinid 
join three on fourth.joinid=three.joinid