Solved

Ambiguous column name

Posted on 2004-08-10
6
1,432 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Designer 19 40
Need a SQL query that creates a header row and one or more detail rows. 7 34
Find SQL query used by application 3 19
sql server tables from access 18 19
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

773 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