Explain the reason for Ambiguous column error in SQL Server 2008

Viewed 2398

I have a table Business_Unit:

    business_unit_id    int
    area_code           nvarchar(100)
    region_code         nvarchar(100)
    sub_region_code     nvarchar(100)

It has some values in it.

Query 1:

select 
    business_unit_id,* 
from 
    business_unit 
order by 
    business_unit_id desc

When I query this, i get the following error.

Msg 209, Level 16, State 1, Line 1
Ambiguous column name 'business_unit_id'.

To solve, I've used the alias name for the table as bu and prefixed the column with the alias name.

select 
    bu.business_unit_id, * 
from 
    business_unit bu 
order by 
    bu.business_unit_id desc

Even the below query works.

select 
    bu.business_unit_id, bu.* 
from 
    business_unit bu 
order by 
    bu.business_unit_id desc

I would like to know, why it threw an error[business_unit_id], with query "Query 1". There is no ambiguity here, I only have one table.

Can you explain?


the reason for asking this question. I have a 120 column table (assume bigtable), now, I want to order it by let say 90 column. I cannot scroll and check the value, hence I put select 90thcolumn,* from bigtable order by 90thcolumn.


4 Answers
Related