Ambiguous Column name'MedianCo' pleas help me

  • update TblGas

    set MedianCo=

    (SELECT MedianCo

    FROM TblGas INNER JOIN

    Total ON TblGas.ID_NO= Total.ID_No

    )

    The above statement gives the following error message

    Ambiguous Column name'MedianCo'

    please help me

  • Qualify your column names. I'm going to guess that the MedianCo in the subquery should be from the Total table?

    update TblGas

    set TblGas.MedianCo=

    (SELECT t.MedianCo

    FROM TblGas AS tg INNER JOIN

    Total AS t ON tg.ID_NO= t.ID_No

    )

    If so, this is an easier way to write that.

    update TblGas

    set TblGas.MedianCo= t.MedianCo

    FROM TblGas INNER JOIN

    Total AS t ON TblGas.ID_NO= t.ID_No

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hi Gail,

    I wonder if there is a difference between your update query and this:

    update TblGas

    set TblGas.MedianCo= t.MedianCo

    FROM Total AS t

    where TblGas.ID_NO= t.ID_No

    when I compeer the Execution Plans they look the same.

  • There have been reported cases where not having the updated table in the from clause has resulted in really odd, inefficient execution plans.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks Gail,

    I knew that there must be some reason for the longer version.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply