SQL Inner join on select statements
Asked Answered
L

4

23

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!

Lenorelenox answered 21/12, 2009 at 14:59 Comment(0)
T
56

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
Theoretics answered 21/12, 2009 at 15:6 Comment(4)
Hi egorius, thanks, it worked. I still don't understand why sometimes oracle accepts the as and sometimes notLenorelenox
'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".Theoretics
You may want to have a look at SELECT syntax diagram (it's quite big, but defines exact syntax): download.oracle.com/docs/cd/B10501_01/server.920/a96540/…Theoretics
I had the same problem that "as" fails when it joins empty table. Without "as" it works.Agamete
D
2

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

Duran answered 21/12, 2009 at 15:6 Comment(0)
D
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)
Diabolic answered 21/12, 2009 at 15:6 Comment(0)
S
1

just give a whitespace between ')' and 'as':

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
Sigismund answered 14/9, 2011 at 5:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.