Showing posts with label HAVING with GROUP BY MYSQL PHP. Show all posts
Showing posts with label HAVING with GROUP BY MYSQL PHP. Show all posts

Friday 16 October 2015

HAVING in mysql PHP


HAVING in mysql PHP

We can not use where keyword with aggregate functions That's why the MySQL HAVING clause uses with aggregate functions. The MySQL HAVING clause is often used with the GROUP BY clause.

For example :

Wrong Query :

$query = 'select count(order_id),customer_id from sales_order group by customer_id where count(order_id) > 10';

Right Query :

$query = 'select count(order_id),customer_id from sales_order group by customer_id HAVING count(order_id) > 10';