Posted inMysql / Mysqli / php

sql having clause Examples

Today, We want to share with you sql having clause.In this post we will show you joins in sql, hear for sql subquery we will give you demo and example for implement.In this post, we will learn about Using SQL Subqueries in UPDATE Statements with an example.

sql having multiple conditions

In this tutorial we learn to all about having Examples like as a SQL COUNT() with HAVING, SQL COUNT( ) with having and group by, Restricting query results, SUM function, COUNT function example, MAX and MIN functions or many more.

Also Read: sql subquery example

Query clause order

  1. SELECT
  2. FROM
  3. WHERE
  4. GROUP BY
  5. HAVING
  6. ORDER BY

SQL COUNT() with HAVING

SELECT COUNT( * ) 
FROM agents 
HAVING COUNT(*)>3;

SQL COUNT( ) with having and group by

SELECT commission, COUNT (*) 
FROM agents 
GROUP BY commission 
HAVING COUNT(*)>3;

Restricting query results using the HAVING clause

SELECT * FROM `movies` GROUP BY `group_id`,`year_released` HAVING `group_id` = 8;

SQL HAVING with SUM function example

SELECT 
    requestid, SUM(unitPrice * quantity) Total
FROM
    requestdetails
GROUP BY requestid
HAVING total > 12000;

SQL HAVING with COUNT function example

SELECT 
    requestID, COUNT(productID) products
FROM
    requestdetails
GROUP BY requestID
HAVING products > 5;

MAX and MIN functions examples

SELECT 
    groupID, productID, productName, MAX(unitprice)
FROM
    products A
WHERE
    unitprice = (
 SELECT 
            MAX(unitprice)
        FROM
            products B
        WHERE
            B.groupId = A.groupID)
GROUP BY groupID;

I hope you get an idea about sql having clause.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype