0

I have a query that looks somewhat like this:

select
  ...,
  my_view.alias_name
from
  tbl1 join
  tbl2 on
    tbl1.key = tbl2.key join
  tbl3 on
    tbl3.key = tbl3.key join
  (
    select
      ...,
      (max(...) keep (...)) alias_name
    from
      ...
  ) my_view on
    tbl3.key = my_view.key
where
  ...;

It doesn't work because the alias_name isn't set (maintaining the name (max(...) keep (...)) which I don't know if its possible to reference in the select my_view.name_or_alias) when I do it this way joining the inline view to the tables, but strangely enough it does work when I join the tables after the inline view instead.

select
  ...,
  my_view.alias_name
from
  (
    select
      ...,
      (max(...) keep (...)) alias_name
    from
      ...
  ) my_view join
  tbl3 on
    my_view.key = tbl3.key join
  tbl2 on
    tbl3.key = tbl2.key join
  tbl1 on
    tbl2.key = tbl1.key
where
  ...;

Is there any explanation or documentation that talks about this or is it undefined/random behavior? Any way to make it work with the inline view joining the tables? I couldn't find any information about this.

user7393973
  • 2,270
  • 1
  • 20
  • 58
  • 3
    "doesn't work" isn't a valid Oracle error message. –  Aug 28 '19 at 09:11
  • 1
    Not agree with you. Please share actual query and actual error. – Popeye Aug 28 '19 at 09:19
  • @a_horse_with_no_name Your comment helped me find out that it's a problem with Microsoft Query which throws the generic error (translated) "It was not possible to add the table 'table_name'." even though after trying the same query on Excel VBA to try getting the Oracle error it does work after all. – user7393973 Aug 28 '19 at 09:21
  • @a_horse_with_no_name Trying `select * from ( select 'X' dummy from dual ) my_view join dual on my_view.dummy = dual.dummy;` [works fine](https://i.imgur.com/TKa3oia.png) while `select * from dual join ( select 'X' dummy from dual ) my_view on dual.dummy = my_view.dummy;` [throws the error](https://i.imgur.com/Gd3Y9un.png) on MS Query but not on VBA (which normally runs the query directly and gives the Oracle errors if there's any). – user7393973 Aug 28 '19 at 09:27

1 Answers1

0

The problem wasn't with Oracle nor the query after all but actually with Microsoft Query itself which was the program that was throwing the error.

It's old and I wish I didn't had to work with it...

Both of the following simplified queries work fine on Excel VBA but the second query doesn't on MS Query.

select
  *
from
  (
    select
      'X' dummy
    from
      dual
  ) my_view join
  dual on
    my_view.dummy = dual.dummy;

Query

select
  *
from
  dual join
  (
    select
      'X' dummy
    from
      dual
  ) my_view on
    dual.dummy = my_view.dummy;

MS Query Error

user7393973
  • 2,270
  • 1
  • 20
  • 58