sqlmysql-error-1054

Error Code: 1054. Unknown column


I have the following SQL statement:

SELECT efforts.user_id, project_tasks.task_name, sum(hours) 
FROM efforts, users, project_tasks
INNER JOIN PROJECT_TASKS pu ON efforts.project_task_id = pu.id  
INNER JOIN USERS u ON efforts.users_id = u.id
WHERE project_tasks.project_id = '2'; 

And when I run it I get the following error:

Error Code: 1054. Unknown column 'efforts.project_task_id' in 'on clause'

Why am I getting this error?

Project_task_id belongs to efforts table

Image of my efforts table

Updated:

SELECT u.full_name, pu.task_name, hours 
FROM efforts
INNER JOIN project_tasks pu ON efforts.project_task_id = pu.id   
INNER JOIN users u ON efforts.user_id = u.id 
GROUP BY user_id, task_name

Solution

  • Your syntax is wrong, it should be:

    SELECT efforts.user_id, pu.task_name, sum(hours)  
    FROM efforts
    INNER JOIN PROJECT_TASKS pu ON efforts.project_task_id = pu.id   
    INNER JOIN USERS u ON efforts.user_id = u.id 
    WHERE pu.project_id = '2';