【问题标题】:simple join sql ambiguous column简单连接sql歧义列
【发布时间】:2015-10-22 03:30:17
【问题描述】:

我收到一个模棱两可的列错误?尽管它们与我选择的所有其他列完全相同。

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

【问题讨论】:

  • 首先不要使用逗号,使用正确的join来连接表

标签: sql join where ambiguous


【解决方案1】:

因为两个表有相同的列名:日期。

你可以试试这个:

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

另外,你应该使用:

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

【讨论】:

    【解决方案2】:

    这样测试

    Select distinct f.date, f.problem, f.companyprofit, f.fixtime    
    from fixandresponse f, netprofit n    
    Where f.date = n.date
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-25
      • 2019-08-25
      • 1970-01-01
      • 2010-09-25
      相关资源
      最近更新 更多