即使表中存在明显相同的名称列,也会出现未知列错误

时间:2013-06-04 10:45:30

标签: php html mysql sql

当我在mysql中运行此查询时

SELECT `projects.proj_id`,`title`,`man_id`,`desc` 
FROM `projects` , `assigned` 
WHERE projects.proj_id=assigned.proj_id  
AND assigned.user_id=1

它返回给我

#1504 Unknown column 'projects.proj_id' in 'field list' 

即使我在项目表中有一个名为proj_id的明确定义的列。我错过了什么吗?我一直在摸不着头脑。

3 个答案:

答案 0 :(得分:3)

封闭时你错过了一些 试试这个:

SELECT `projects`.`proj_id`,`title`,`man_id`,`desc` 
FROM `projects` , `assigned` 
WHERE projects.proj_id=assigned.proj_id  
AND assigned.user_id=1

答案 1 :(得分:3)

您已选择projects.proj_id作为列,您应该选择它 试试这个

   SELECT projects.proj_id,title,man_id,`desc` 
   FROM projects , assigned 
   WHERE projects.proj_id=assigned.proj_id  
   AND assigned.user_id=1

或更好地使用JOIN

      SELECT p.proj_id,title,man_id,`desc` 
      FROM projects p
      INNER JOIN  assigned a
      ON  p.proj_id=a.proj_id  
      WHERE assigned.user_id=1

答案 2 :(得分:2)

试试这个: SELECT projects.proj_id,title,man_id,desc 来自项目,已分配 WHERE projects.proj_id = assigned.proj_id
AND assigned.user_id = 1