Question

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
Was it helpful?

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';  

OTHER TIPS

Note that as far as I know, MySQL is case-sensitive on table names (not on column names)... That might cause some trouble in your query...? Along with StevieG's correction

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top