• Dineshbabu (1/17/2013)


    Great question and great concept.

    I added COL1 to TblA2 and expected "Ambiguous column name 'col1'.". But this time Sql server selected column from TblA2 and gave me the correct result.

    It will be failed in Joins if we didn't prefix the table with alias name.

    That's correct. SQL Server will first try to match an unqualified column reference in the current scope. If that fails, it will go one scope higher, and repeat that as necessary. You will only get the "ambiguous column name" error if there are multiple columns with the same name at the same level.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/