0

我正在使用 MySql。当我从表中选择多列时

负责人ID,职务

然后生成错误。所以我不会选择多列。请帮我解决这个问题。

 select id,
        title,
        responsible_id,
        project_id p_id,(select responsible_id,title from projects where p_id=projects.project_id) responsible_id,
        status,
        create_by,
        milestone_id from tasks
4

1 回答 1

2

通过这种方式,您不能从相关子查询中选择多个列。

JOIN而是两个表,如下所示:

 select 
   t.id,
   t.title AS TaskTitle,
   t.responsible_id,
   p.project_id p_id,
   p.responsible_id,
   p.title AS ProjectTitle,
   t.status,
   t.create_by,
   t.milestone_id
from tasks AS t
INNER JOIN projects AS p ON t.p_id = p.project_id
于 2013-02-18T11:46:43.370 回答