Skip to content
Advertisement

ERROR 1054 (42S22): Unknown column ‘pc.project_id’ in ‘on clause’ even when column project_id exists

I am trying to get a sum from my DB with a query written in hibernate

@Query(value = "SELECT COALESCE(sum(charge),0) FROM initial_charge I INNER JOIN task T ON T.id = I.task_id "
+" INNER JOIN project_collab PC ON PC.collab_id=T.collaborator_id "
        + " INNER JOIN project P ON P.id = pc.project_id "
+ "where P.id = :idProject AND T.collaborator_id = :idCollab ", nativeQuery = true)
double sumInitialChargeByCollab(@Param("idProject") int idProject , @Param("idCollab") int idCollab);

The problem is, I get nothing in return. When I tried it directly in mysql I got this error :

ERROR 1054 (42S22): Unknown column 'pc.project_id' in 'on clause'

even though the column exists in the table

enter image description here

Advertisement

Answer

The query text cleared from external code dirt is:

SELECT COALESCE(sum(charge),0) 
FROM initial_charge I 
INNER JOIN task T ON T.id = I.task_id 
INNER JOIN project_collab PC ON PC.collab_id=T.collaborator_id 
INNER JOIN project P ON P.id = pc.project_id 
where P.id = :idProject 
  AND T.collaborator_id = :idCollab

If case-dependence is enabled then PC and pc are two different names.

Convert ALL table/column/alias names to the same case (lower preferred).

PS. If charge (by the way, what table does this field come from?) is not nullable then COALESCE is excess.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement