3

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
Deej
  • 5,334
  • 12
  • 44
  • 68

2 Answers2

8

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';  
StevieG
  • 8,639
  • 23
  • 31
  • The last line should be: WHERE pu.project_id = '2'; – Klas Lindbäck Sep 07 '11 at 11:48
  • @Klas Lindbäck I tried this and it didn't work I got this error `Error Code: 1054. Unknown column 'project_tasks.task_name' in 'field list'` – Deej Sep 07 '11 at 11:49
  • Thanks, Okay I tried this and now it thrown up this error `Error Code: 1054. Unknown column 'efforts.users_id' in 'on clause'`. – Deej Sep 07 '11 at 11:51
  • I tried this and it worked thank you. I extended the query so that it looks like the following. I've updated my post – Deej Sep 07 '11 at 14:24
2

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

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509