Solved

Ambiguous column name

Posted on 2004-08-10
6
1,437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

691 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