Search code examples
sqljoinwhere-clauseambiguous

simple join sql ambiguous column


I'm getting an ambiguous column error? Even though they are exactly the same like all the other columns that I selected.

SELECT DISTINCT [date], [problem], [companyprofit], [fixtime]
FROM [fixandresponse]  , [netprofit] 
WHERE [fixandresponse].[date] = [netprofit].[date]

Solution

  • Because two table have a same column name: date.

    You can try this:

    SELECT DISTINCT [fixandresponse].[date], [problem], [companyprofit], [fixtime]
    FROM [fixandresponse]  , [netprofit] 
    WHERE [fixandresponse].[date] = [netprofit].[date]
    

    Also, you should use:

    SELECT DISTINCT F.[date], F...., N.... -- get column from two table
    FROM [fixandresponse] F
      INNER JOIN [netprofit] N
        ON F.[date] = N.[date]