Unix Technical Forum

ORA-00918: column ambiguously defined

This is a discussion on ORA-00918: column ambiguously defined within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Hi, I am getting the above error when I try and run the query below on bb.tab_urn. However, removing ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 12:20 PM
timothy.hill@gmail.com
 
Posts: n/a
Default ORA-00918: column ambiguously defined

Hi,

I am getting the above error when I try and run the query below on
bb.tab_urn. However, removing this group by then gives the same error,
but at bb.transaction_date. Unless I have missed something completely,
I am certain I have defined everything correctly. Thoughts? Any help
would be very much appreciated!

Cheers

Tim

select com.name
, curr.quantity
, prev.quantity
from ( select count(*) as quantity
, a.tab_urn
from v_rep_vehicle_check_3m_trans a
where a.CLASS_CODE in ('TDCP', 'TDCC')
and a.TRANSACTION_DATE between
to_date('2007-01-01000000','YYYY-MM-DDHH24MISS')
and
to_date('2007-01-31235929','YYYY-MM-DDHH24MISS')
and a.tab_urn not in (0,10)
group by a.tab_urn) curr
full outer join
( select count(*) as quantity
, bb.tab_urn
from v_rep_vehicle_check_3m_trans bb
where bb.CLASS_CODE in ('TDCP', 'TDCC')
and bb.transaction_date between
add_months(to_date('2007-01-01000000','YYYY-MM-DDHH24MISS'),-1)
and
add_months(to_date('2007-01-31235929','YYYY-MM-DDHH24MISS'),-1)
and bb.tab_urn not in (0,10)
group by bb.TAB_URN) prev
on prev.tab_urn = curr.tab_urn
, rep_curr_company com
where curr.tab_urn = com.tab_urn
OR prev.tab_urn = com.tab_urn
order by
com.name;

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 12:20 PM
Mark D Powell
 
Posts: n/a
Default Re: ORA-00918: column ambiguously defined

On Feb 20, 8:33 am, timothy.h...@gmail.com wrote:
> Hi,
>
> I am getting the above error when I try and run the query below on
> bb.tab_urn. However, removing this group by then gives the same error,
> but at bb.transaction_date. Unless I have missed something completely,
> I am certain I have defined everything correctly. Thoughts? Any help
> would be very much appreciated!
>
> Cheers
>
> Tim
>
> select com.name
> , curr.quantity
> , prev.quantity
> from ( select count(*) as quantity
> , a.tab_urn
> from v_rep_vehicle_check_3m_trans a
> where a.CLASS_CODE in ('TDCP', 'TDCC')
> and a.TRANSACTION_DATE between
> to_date('2007-01-01000000','YYYY-MM-DDHH24MISS')
> and
> to_date('2007-01-31235929','YYYY-MM-DDHH24MISS')
> and a.tab_urn not in (0,10)
> group by a.tab_urn) curr
> full outer join
> ( select count(*) as quantity
> , bb.tab_urn
> from v_rep_vehicle_check_3m_trans bb
> where bb.CLASS_CODE in ('TDCP', 'TDCC')
> and bb.transaction_date between
> add_months(to_date('2007-01-01000000','YYYY-MM-DDHH24MISS'),-1)
> and
> add_months(to_date('2007-01-31235929','YYYY-MM-DDHH24MISS'),-1)
> and bb.tab_urn not in (0,10)
> group by bb.TAB_URN) prev
> on prev.tab_urn = curr.tab_urn
> , rep_curr_company com
> where curr.tab_urn = com.tab_urn
> OR prev.tab_urn = com.tab_urn
> order by
> com.name;


I am not the most observant person so naturally I did not spot the
error. But what version of Oracle is this?

Try changing quantity to a unique name every where it appears in an
inline view and prefix the one or two columns you did not prefix. If
doin this does not identify and fix the problem I suggest rewriting
the query to use traditional syntax.

HTH -- Mark D Powell --

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 12:20 PM
timothy.hill@gmail.com
 
Posts: n/a
Default Re: ORA-00918: column ambiguously defined

On 20 Feb, 13:47, "Mark D Powell" <Mark.Pow...@eds.com> wrote:
> On Feb 20, 8:33 am, timothy.h...@gmail.com wrote:
>
>
>
> > Hi,

>
> > I am getting the above error when I try and run the query below on
> > bb.tab_urn. However, removing this group by then gives the same error,
> > but at bb.transaction_date. Unless I have missed something completely,
> > I am certain I have defined everything correctly. Thoughts? Any help
> > would be very much appreciated!

>
> > Cheers

>
> > Tim

>
> > select com.name
> > , curr.quantity
> > , prev.quantity
> > from ( select count(*) as quantity
> > , a.tab_urn
> > from v_rep_vehicle_check_3m_trans a
> > where a.CLASS_CODE in ('TDCP', 'TDCC')
> > and a.TRANSACTION_DATE between
> > to_date('2007-01-01000000','YYYY-MM-DDHH24MISS')
> > and
> > to_date('2007-01-31235929','YYYY-MM-DDHH24MISS')
> > and a.tab_urn not in (0,10)
> > group by a.tab_urn) curr
> > full outer join
> > ( select count(*) as quantity
> > , bb.tab_urn
> > from v_rep_vehicle_check_3m_trans bb
> > where bb.CLASS_CODE in ('TDCP', 'TDCC')
> > and bb.transaction_date between
> > add_months(to_date('2007-01-01000000','YYYY-MM-DDHH24MISS'),-1)
> > and
> > add_months(to_date('2007-01-31235929','YYYY-MM-DDHH24MISS'),-1)
> > and bb.tab_urn not in (0,10)
> > group by bb.TAB_URN) prev
> > on prev.tab_urn = curr.tab_urn
> > , rep_curr_company com
> > where curr.tab_urn = com.tab_urn
> > OR prev.tab_urn = com.tab_urn
> > order by
> > com.name;

>
> I am not the most observant person so naturally I did not spot the
> error. But what version of Oracle is this?
>
> Try changing quantity to a unique name every where it appears in an
> inline view and prefix the one or two columns you did not prefix. If
> doin this does not identify and fix the problem I suggest rewriting
> the query to use traditional syntax.
>
> HTH -- Mark D Powell --


Hi Mark,

Thanks for your quick reply. The version I am using is Oracle 10g. I
have tried what you suggested, but no joy. You say traditional syntax
- could you give me an example? Whilst I can use SQL to a certain
degree, I don't think I am as competent as I would like (illustrated
by my query I think!) So any help anyone can offer would be great!

Cheers

Tim

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 12:20 PM
William Robertson
 
Posts: n/a
Default Re: ORA-00918: column ambiguously defined

On Feb 20, 2:07 pm, timothy.h...@gmail.com wrote:
> On 20 Feb, 13:47, "Mark D Powell" <Mark.Pow...@eds.com> wrote:
>
>
>
> > On Feb 20, 8:33 am, timothy.h...@gmail.com wrote:

>
> > > Hi,

>
> > > I am getting the above error when I try and run the query below on
> > > bb.tab_urn. However, removing this group by then gives the same error,
> > > but at bb.transaction_date. Unless I have missed something completely,
> > > I am certain I have defined everything correctly. Thoughts? Any help
> > > would be very much appreciated!

>
> > > Cheers

>
> > > Tim

>
> > > select com.name
> > > , curr.quantity
> > > , prev.quantity
> > > from ( select count(*) as quantity
> > > , a.tab_urn
> > > from v_rep_vehicle_check_3m_trans a
> > > where a.CLASS_CODE in ('TDCP', 'TDCC')
> > > and a.TRANSACTION_DATE between
> > > to_date('2007-01-01000000','YYYY-MM-DDHH24MISS')
> > > and
> > > to_date('2007-01-31235929','YYYY-MM-DDHH24MISS')
> > > and a.tab_urn not in (0,10)
> > > group by a.tab_urn) curr
> > > full outer join
> > > ( select count(*) as quantity
> > > , bb.tab_urn
> > > from v_rep_vehicle_check_3m_trans bb
> > > where bb.CLASS_CODE in ('TDCP', 'TDCC')
> > > and bb.transaction_date between
> > > add_months(to_date('2007-01-01000000','YYYY-MM-DDHH24MISS'),-1)
> > > and
> > > add_months(to_date('2007-01-31235929','YYYY-MM-DDHH24MISS'),-1)
> > > and bb.tab_urn not in (0,10)
> > > group by bb.TAB_URN) prev
> > > on prev.tab_urn = curr.tab_urn
> > > , rep_curr_company com
> > > where curr.tab_urn = com.tab_urn
> > > OR prev.tab_urn = com.tab_urn
> > > order by
> > > com.name;

>
> > I am not the most observant person so naturally I did not spot the
> > error. But what version of Oracle is this?

>
> > Try changing quantity to a unique name every where it appears in an
> > inline view and prefix the one or two columns you did not prefix. If
> > doin this does not identify and fix the problem I suggest rewriting
> > the query to use traditional syntax.

>
> > HTH -- Mark D Powell --

>
> Hi Mark,
>
> Thanks for your quick reply. The version I am using is Oracle 10g. I
> have tried what you suggested, but no joy. You say traditional syntax
> - could you give me an example? Whilst I can use SQL to a certain
> degree, I don't think I am as competent as I would like (illustrated
> by my query I think!) So any help anyone can offer would be great!
>
> Cheers
>
> Tim


I can't see an error either but it might be worth putting that final
join into ANSI syntax rather than switching back to a where-clause
join. You might also try moving the inline views into WITH clauses
e.g.

WITH curr AS ( SELECT COUNT(*) AS quantity ... )
, prev AS ( SELECT COUNT(*) AS quantity ... )
SELECT com.name
, curr.quantity
, prev.quantity ...
FROM curr
, prev
, rep_curr_company com
WHERE ...

However I'm afraid this is a case of nudging it and seeing what it
does rather than getting to the root of the problem. Possibly the CBO
is rewriting the query in some way and running into a bug.

Possibly I'm missing something but the join oerder seems a bit odd.
You are full outer joining two inline views and then inner joining
then to a third table, with an 'or' condition. Shouldn't you start
with rep_curr_company and then left outer join each of the two views
to that?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-08-2008, 12:21 PM
Mark D Powell
 
Posts: n/a
Default Re: ORA-00918: column ambiguously defined

On Feb 20, 9:07 am, timothy.h...@gmail.com wrote:
> On 20 Feb, 13:47, "Mark D Powell" <Mark.Pow...@eds.com> wrote:
>
>
>
>
>
> > On Feb 20, 8:33 am, timothy.h...@gmail.com wrote:

>
> > > Hi,

>
> > > I am getting the above error when I try and run the query below on
> > > bb.tab_urn. However, removing this group by then gives the same error,
> > > but at bb.transaction_date. Unless I have missed something completely,
> > > I am certain I have defined everything correctly. Thoughts? Any help
> > > would be very much appreciated!

>
> > > Cheers

>
> > > Tim

>
> > > select com.name
> > > , curr.quantity
> > > , prev.quantity
> > > from ( select count(*) as quantity
> > > , a.tab_urn
> > > from v_rep_vehicle_check_3m_trans a
> > > where a.CLASS_CODE in ('TDCP', 'TDCC')
> > > and a.TRANSACTION_DATE between
> > > to_date('2007-01-01000000','YYYY-MM-DDHH24MISS')
> > > and
> > > to_date('2007-01-31235929','YYYY-MM-DDHH24MISS')
> > > and a.tab_urn not in (0,10)
> > > group by a.tab_urn) curr
> > > full outer join
> > > ( select count(*) as quantity
> > > , bb.tab_urn
> > > from v_rep_vehicle_check_3m_trans bb
> > > where bb.CLASS_CODE in ('TDCP', 'TDCC')
> > > and bb.transaction_date between
> > > add_months(to_date('2007-01-01000000','YYYY-MM-DDHH24MISS'),-1)
> > > and
> > > add_months(to_date('2007-01-31235929','YYYY-MM-DDHH24MISS'),-1)
> > > and bb.tab_urn not in (0,10)
> > > group by bb.TAB_URN) prev
> > > on prev.tab_urn = curr.tab_urn
> > > , rep_curr_company com
> > > where curr.tab_urn = com.tab_urn
> > > OR prev.tab_urn = com.tab_urn
> > > order by
> > > com.name;

>
> > I am not the most observant person so naturally I did not spot the
> > error. But what version of Oracle is this?

>
> > Try changing quantity to a unique name every where it appears in an
> > inline view and prefix the one or two columns you did not prefix. If
> > doin this does not identify and fix the problem I suggest rewriting
> > the query to use traditional syntax.

>
> > HTH -- Mark D Powell --

>
> Hi Mark,
>
> Thanks for your quick reply. The version I am using is Oracle 10g. I
> have tried what you suggested, but no joy. You say traditional syntax
> - could you give me an example? Whilst I can use SQL to a certain
> degree, I don't think I am as competent as I would like (illustrated
> by my query I think!) So any help anyone can offer would be great!
>
> Cheers
>
> Tim- Hide quoted text -
>
> - Show quoted text -


Similar to
from table1 a, table2 b, table3 c
where a.key = b.key(+)
and a.key = c.key(+)

You just list the tables in the FROM clause and you just list the ON
conditions in the WHERE clause. The plus sign in () is the
traditional outer join symbol in Oracle. The plus goes on the side
(table) which returns NULL when there is no match so that the
receiving table on the other side of the relational operator alwyas
returns a row.

HTH -- Mark D Powell --

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-08-2008, 12:21 PM
G Quesnel
 
Posts: n/a
Default Re: ORA-00918: column ambiguously defined

On Feb 20, 8:33 am, timothy.h...@gmail.com wrote:
> Hi,
>
> I am getting the above error when I try and run the query below on
>
> select com.name
> , curr.quantity
> , prev.quantity
> from ( select count(*) as quantity
> , a.tab_urn


Would the second and third columns not be named the same (ie
QUANTITY).
How about providing a column alias, as in ...
select com.name,curr.quantity "Curr_Quantity", prev.quantity
"Prev_Quantity" from ...

Hth

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:57 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com