Solved

Ambiguous column name

Posted on 2004-08-10
6
1,427 Views
Last Modified: 2008-01-09
I have a coloum called OBCUSD within a table and when ever i run a sum on this coloum i get a "Ambiguous column name" error appear.

A: what is this
B: how can i over come it? I tried to do a SELECT OBCUSD AS 'OTHER_NAME' But this did not work for the query that i want and then it want me to group By this field

willa
0
Comment
Question by:willa666
6 Comments
 
LVL 39

Expert Comment

by:appari
ID: 11760312

can you post the query you were trying to execute?
0
 
LVL 26

Accepted Solution

by:
Hilaire earned 125 total points
ID: 11760342
Most likely your query performs a select using JOINs on several tables
The "Ambiguous columnn name" error means that the column name can be found in several tables, so you have to use more qualified names, either using the table name as a prefix, or an alias if you use some

SELECT YOURTABLE.OBCUSD , .....
or

SELECT a.OBSCUSD, ......
FROM YOURTABLE a INNER JOIN ....
0
 

Expert Comment

by:candelaboy
ID: 11760393
please paste your sql query.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 5

Expert Comment

by:amit1978
ID: 11760611
Hello willa,

This error occure if an query haveing coloumn of same name (weather ur useing thous column in query or not) in two different table and table name or alins is not prefix with that column.

what u have to specify the table name before the column name.

amit

0
 
LVL 1

Expert Comment

by:dacz
ID: 11760938
i think amit1978 is right.
0
 
LVL 1

Expert Comment

by:jasonwisdom
ID: 11763530
This happens when two returned fields have the same name.  For example,

SELECT a.id, a.name, b.id, b.name
FROM users a, addresses b
WHERE b.id=a.id

You'll still get two duplicate sets of columns, two each of "id" and "name".

Much better is to include AS clauses, for example this:

SELECT a.id AS userid, a.name AS username, b.id AS addressid, b.name AS addressname
FROM users a, addresses b
WHERE b.id=a.id

Using an AS identifier is called using an alias.

Moreso than specifying (tablename).(fieldname), you should re-alias your returned fields so your recordset, datareader, etc. knows what to grab when it's specifying a column by name.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now