0

Fairly basic ; Invalid group function. i know i need to be using HAVING but not sure how to rewrite it.

update deals d 
join deal_products dp on dp.deal_id = d.id
set d.products_count = count(distinct product_id)
where dp.active_flag=1 and dp.enabled_flag=1 and d.status != 'deleted';
b0uncyfr0
  • 177
  • 2
  • 2
  • 10
  • Possible duplicate of [Is there ANY\_VALUE capability for mysql 5.6?](http://stackoverflow.com/questions/37089347/is-there-any-value-capability-for-mysql-5-6) – e4c5 Sep 30 '16 at 00:01

1 Answers1

0

You can't use an aggregation function like count without a group by and assign this value as a result
In this case you should use a proper subselect for obtain the value to assign at d.products_count

update deals d 
join deal_products dp on dp.deal_id = d.id
set d.products_count = (select count(distinct product_id) 
                         from  your_table  where Your_condition)
where dp.active_flag=1 and dp.enabled_flag=1 and d.status != 'deleted';
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107