willa666
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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.
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.
can you post the query you were trying to execute?