2009-12-21 86 views
14

我试图让内连接在SELECT语句是这样的:SQL内连接的SELECT语句

select * 
from (select* from bars where rownum <= 10)as tab1 
inner join (select * from bars where rownum <= 10)as tab2 
on tab1.close=tab2.close 

,我得到以下错误: ORA-00933 SQL命令不能正确地结束 任何帮助将不胜感激,谢谢!

回答

39

刚刚从查询中删除as

select * 
from (select* from bars where rownum <= 10) tab1 
inner join (select * from bars where rownum <= 10) tab2 
on tab1.close=tab2.close 
+1

嗨egorius,谢谢,它的工作。我仍然不明白为什么有时候oracle会接受as,有时候不接受 – user235693 2009-12-21 16:07:04

+5

'As'可以(可选)在COLUMN别名之前使用。 'TABLE'别名不能用'as'作为前缀。例如:“从双d选择count(*)cnt”。 – 2009-12-21 20:02:46

+1

您可能想看看SELECT语法图(它非常大,但定义了精确的语法):http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#SQLRF01702 – 2009-12-21 20:05:45

1
select * from 
((select* from bars where rownum <= 10)as tab1 
inner join (select * from bars where rownum <= 10)as tab2 
on tab1.close=tab2.close) 
2

我相信,错误来自于你需要一个分号结束发言。否则,选择看起来不错。

1

只给 ')' 之间的空格和 '为':

select * from (select* from bars where rownum <= 10) as tab1 
inner join 
(select * from bars where rownum <= 10) as tab2 
on 
tab1.close=tab2.close