2014-08-27 192 views
0

誰能幫我這個問題,我試過很多次,但還沒有找到解決辦法 這裏原來認爲我在我的數據庫,但現在我做數據庫的變化和該觀點也需要改變。SQL視圖語句連接

這是因爲它認爲:

SELECT 
    [tableN].*, 
    [tabB].[att1] AS tabB_email, [tabB].[name] AS tabB_name, 
    [tabC].[name] AS tabC_name 
FROM 
    [tabC] 
INNER JOIN 
    ([tableN] 
INNER JOIN [tabB] ON [tableN].[sender_id] = [tabB].[ID]) 
    ON [tabC].[ID] = [tableN].[recipient_id] 

這裏是什麼對我來說是難點。現在我沒有這個2個表tabBtabC

他們現在在一個表tabX並有一個標識符字段roleId。我設法得到除了最後一個[tabC].[name] AS tabC_name

任何想法都列?

+0

remvoe'[TABC]代碼。[名]'和'刪除在tabc'從caluse變化塔布到TABX – Sathish 2014-08-27 08:51:52

+0

但我需要的tabC_name女巫是同一個領域tabB_name但現在有diferent ID和角色ID。需要顯示的名字 – 2014-08-27 08:54:57

+0

能否請您SQLFiddle表模式?或者在你的問題中提供表格結構與它的關係? – 2014-08-27 08:56:40

回答

0
SELECT [TableN].*, Bd.[email] AS bd_email, Bd.[showname] AS bd_name, 
     Pc.[showname] AS pc_name 
    FROM 
     [TABLE_X] AS Pc 
     INNER JOIN ([TableN] 
     INNER JOIN [TABLE_X] AS Bd 
     ON [TableN].[sender_id] = Bd.[ID] AND Bd.roleID = 1) 
     ON Pc.[ID] = [TableN].[recipient_id] AND Pc.roleID = 2 

我終於找到了正在工作的需要

0
SELECT [tableN].*, [Tabx] .[att1] AS tabB_email, [Tabx] .[name] AS tabB_name 

    FROM [Tabx] A 

    INNER JOIN [TABLEN] B 

    ON A.ROLEID=B.RECIPIENT_ID 
0

嘗試這樣

SELECT [tableN].*, [tabX].[att1] AS tabB_email, [tabX].[name] AS tabB_name, 
t1.[name] AS tabC_name 
FROM [tabX] as t INNER JOIN ([tableN] INNER JOIN [tabX] 
ON [tableN].[sender_id] = [tabX].[roleid]) 
ON t.[roleid] = [tableN].[recipient_id] 
+0

'[tabB]'不存在。 – 2014-08-27 09:03:55

+0

@RuslanVeselov現在檢查它 – Sathish 2014-08-27 09:07:06

+0

我得到了列的名稱,但沒有數據:/ – 2014-08-27 09:08:10