dbTalk Databases Forums  

Invalid column name

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Invalid column name in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Christian
 
Posts: n/a

Default Invalid column name - 05-20-2005 , 02:37 PM






Hello,

If I do :

(select 0, c.*
from table1 c
minus
select distinct 0, a.*
from table1 a,table2 b
where ... )
union
select distinct 1, a.*
from table1 a, table2 b
where ...

it works fine.

But if I want to add "order by" and any column from table1 I get
"ORA-00904 invalid column name"

I don't understand :-(

Thanks in advance for any idea...

Reply With Quote
  #2  
Old   
Mark C. Stock
 
Posts: n/a

Default Re: Invalid column name - 05-20-2005 , 04:00 PM







"Christian" <c> wrote

Quote:
Hello,

If I do :

(select 0, c.*
from table1 c
minus
select distinct 0, a.*
from table1 a,table2 b
where ... )
union
select distinct 1, a.*
from table1 a, table2 b
where ...

it works fine.

But if I want to add "order by" and any column from table1 I get
"ORA-00904 invalid column name"

I don't understand :-(

Thanks in advance for any idea...
1) post the statement that causes the error
2) you probably need to order by column position, not column name, since
you're using set operators

++ mcs




Reply With Quote
  #3  
Old   
Christian
 
Posts: n/a

Default Re: Invalid column name - 05-20-2005 , 04:43 PM



Mark C. Stock wrote:

Quote:
1) post the statement that causes the error
2) you probably need to order by column position, not column name, since
you're using set operators
Simply "order by table1.col1" causes this error, or any other column of
table1.
But I can't use column position because it could change.
I 've put a.* or c.* because there are too many columns...


Reply With Quote
  #4  
Old   
Barbara Boehmer
 
Posts: n/a

Default Re: Invalid column name - 05-21-2005 , 01:17 AM



Try using the whole thing as a subquery and wrapping one more query
around it, with the order by clause in the outer query, and just using
the column name in the order by clause without prefacing it with a
table name, as demonstrated below.

scott@ORA92> create table table1 as select * from dept
2 /

Table created.

scott@ORA92> create table table2 as select * from dept where deptno =
10
2 /

Table created.

scott@ORA92> select *
2 from ((select 0, c.*
3 from table1 c
4 minus
5 select 0, a.*
6 from table1 a, table2 b
7 where a.deptno = b.deptno)
8 union
9 select 1, a.*
10 from table1 a, table2 b
11 where a.loc = b.loc)
12 order by dname
13 /

0 DEPTNO DNAME LOC
---------- ---------- -------------- -------------
1 10 ACCOUNTING NEW YORK
0 40 OPERATIONS BOSTON
0 20 RESEARCH DALLAS
0 30 SALES CHICAGO

scott@ORA92>


Reply With Quote
  #5  
Old   
Christian
 
Posts: n/a

Default Re: Invalid column name - 05-21-2005 , 01:48 AM



Barbara Boehmer wrote:
Quote:
Try using the whole thing as a subquery and wrapping one more query
around it, with the order by clause in the outer query, and just using
the column name in the order by clause without prefacing it with a
table name, as demonstrated below.
Ah, yes.
I can't test for now, but, according to your sample, it should work.
Many thanks !


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.