Link to home
Start Free TrialLog in
Avatar of willa666
willa666Flag for United States of America

asked on

Ambiguous column name

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
Avatar of appari
appari
Flag of India image


can you post the query you were trying to execute?
ASKER CERTIFIED SOLUTION
Avatar of Hilaire
Hilaire
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of candelaboy
candelaboy

please paste your sql query.
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

i think amit1978 is right.
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.