2013-05-13 229 views
0

我試圖在SQL中連接三個表。 我使用下面的查詢,但它不工作sql中的左右連接

select * 
from char_level as c1 right join (SELECT distinct character_id as fid, target_character_dbid as tid FROM house 
where reason='set_house_access' or reason='remove_house_access' and character_id is not null and target_character_dbid is not null)as vd on c1.character_id==vd.fid left join char_level as c2 on c2.character_id==vd.tid 

誰能幫助?

+0

查詢不執行:錯誤ORA-00933:SQL命令不能正確地結束 00933. 00000 - 「SQL命令不能正確地結束」 *原因: *動作: 行錯誤:38列: 17 – 2013-05-13 20:39:02

+0

我期望結果應該是包含c1.account_id,vd.fid,vd.tid,c2.accoutn_id – 2013-05-13 20:40:10

+0

的單個表Oracle對於表別名中的'AS'關鍵字有反感。刪除它(除了其他更正,在答案。)'從char_level爲c1'應該從'char_level c1'和')作爲vd'應該變成:')vd' – 2013-05-13 21:08:49

回答

2

添加分號並使用單個等號。

select * 
from char_level c1 
right join 
(SELECT distinct character_id as fid, target_character_dbid as tid 
FROM house 
where (reason = 'set_house_access' 
or reason = 'remove_house_access') 
and character_id is not null 
and target_character_dbid is not null) vd 
on c1.character_id = vd.fid 
left join char_level c2 
on c2.character_id = vd.tid; 
+0

它仍然給出錯誤 – 2013-05-13 20:48:50

+0

也許你有兩個語句連接成一個沒有分號的單個語句。你有什麼在線:38列:17?在Oracle的每個語句後都需要分號,否則您會收到此錯誤消息,[請參閱此處的示例](http://stackoverflow.com/questions/72151/ora-00933-sql-command-not-properly-ended)。我希望這有幫助! – criticalfix 2013-05-13 20:54:02

+0

我試過了你發佈的查詢,但是stil出現了錯誤 – 2013-05-13 21:02:12