tags:

views:

181

answers:

4

Hello, I am trying to make an inner join on a select statement like this:

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

and I get the following error: ORA-00933 SQL command not properly ended Any help would be appreciated, thank you!

+3  A: 

Just remove as from your query:

select *
from (select* from bars  where rownum <= 10 ) tab1
inner join (select * from bars  where rownum <= 10 ) tab2
on tab1.close=tab2.close
egorius
Hi egorius, thanks, it worked. I still don't understand why sometimes oracle accepts the as and sometimes not
'As' can be (optionally) used before a COLUMN alias. TABLE aliases can't be prepended by 'as'. For example: "select count(*) as cnt from dual d".
egorius
You may want to have a look at SELECT syntax diagram (it's quite big, but defines exact syntax): http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#SQLRF01702
egorius
A: 
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)
Ozan BAYRAM
A: 

I believe the error comes from you needing a semicolon to end the statement. The select looks fine to me otherwise.

Wade73
A: 

Not related to your error message, but I think you need an ORDER BY in there somewhere, as otherwise there's no guarantee as to which top 10 rows you're going to get:

...
select* from bars  order by <some col> where rownum <= 10
...

See here for more info:

http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html

davek