0

我正在尝试加入 3 个表,但我的查询一直出错。我不确定我做错了什么。我的语法一定是做错了什么,但我不太确定哪里出了问题。

SELECT project_timecard_tasks.DateTime,
        project_timecard_tasks.Total_Hours,
        project_timecard_tasks.User_ID,
        project_timecard_tasks.Task_ID,
        project_timecard_tasks.Project_ID,
        users.User_ID,
        users.FirstName,
        users.LastName,
        tasks.id,
        tasks.taskName

 FROM project_timecard_tasks

 JOIN project_timecard_tasks ON project_timecard_tasks.User_ID = users.User_ID 
 AND project_timecard_tasks.Task_ID = tasks.id

 WHERE project_timecard_tasks.Project_ID = '$jobNumber'
4

4 回答 4

2

你的JOIN说法有点不靠谱。试试这个:

SELECT project_timecard_tasks.DateTime,
        project_timecard_tasks.Total_Hours,
        project_timecard_tasks.User_ID,
        project_timecard_tasks.Task_ID,
        project_timecard_tasks.Project_ID,
        users.User_ID,
        users.FirstName,
        users.LastName,
        tasks.id,
        tasks.taskName

 FROM project_timecard_tasks

 JOIN users ON project_timecard_tasks.User_ID = users.User_ID 
 JOIN tasks ON project_timecard_tasks.Task_ID = tasks.id

 WHERE project_timecard_tasks.Project_ID = '$jobNumber'
于 2012-06-12T04:38:12.873 回答
0

您正在从三个表中选择数据,(project_timecard_tasks , users and tasks)但在from子句中您只提到 1 个表。您需要提及所有表名称,例如:

 FROM project_timecard_tasks ,users, tasks
于 2012-06-12T04:30:36.640 回答
0

你 JOIN 不正确。您需要指定要加入的表。将其替换为:

JOIN users ON project_timecard_tasks.User_ID = users.User_ID 
JOIN tasks ON project_timecard_tasks.Task_ID = tasks.id
于 2012-06-12T04:42:53.580 回答
0

在第二个连接语句中 删除AND并使用。JOIN

JOIN project_timecard_tasks ON project_timecard_tasks.User_ID = users.User_ID JOIN project_timecard_tasks.Task_ID = tasks.id

于 2012-06-12T04:46:55.150 回答