Mysql error Invalid use of group function -


    select     c.investor_id investorid,     i.name investor_name,     inv_typ.name type_of_investor,     (select count(*) investor_users user_id=iu.user_id) num_of_investors,     (select count(*) task_logs campaign_id=c.id) num_of_task_logs,     c.updated_at updated_date,     c.call_date calldate,     a.name admin_name,     c.id campaign_id       admins a,     investors i,     investor_types inv_typ,     campaigns c,     task_logs tl,     campaign_statuses cs,     investor_users iu       c.investor_id=i.id     , i.investor_type_id=inv_typ.id     , i.id=iu.investor_id     , c.campaign_status_id = cs.id     , c.assigned_to_admin_id = a.id     , c.campaign_type_id = 1     , c.campaign_status_id = (select id campaign_statuses having id=c.campaign_status_id , cs.code ='closed') , c.assigned_to_admin_id = 46     , tl.campaign_id = c.id , max((select task_logs.task_status_id task_logs having task_logs.campaign_id = c.id)) = 9   order c.call_date asc 

you have max() in where clause:

max((select task_logs.task_status_id      task_logs      having task_logs.campaign_id = c.id)) = 9 

that improper use of aggregation function. instead:

(select max(task_logs.task_status_id)  task_logs  task_logs.campaign_id = c.id) = 9 

this glaring error easy spot, because audacious. however, query benefit following:

  • never use commas in from clause. always use proper explicit join syntax. proper way express joins 2 decades, time use it.
  • use table aliases queries easier write , read.
  • don't confuse having clause where clause. subquery should have used where.

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -