---
title: "Use of Group by and Having Clause in Sql Server"  
description: "Use of Group by and Having Clause in Sql Server"  
author: "Anonymous User"  
published: 2015-11-30  
updated: 2015-11-30  
canonical: https://www.mindstick.com/forum/33663/use-of-group-by-and-having-clause-in-sql-server  
category: "database"  
tags: ["sql server", "sql"]  
reading_time: 1 minute  

---

# Use of Group by and Having Clause in Sql Server

I want to use [Group by and Having](https://www.mindstick.com/interview/23189/what-is-the-use-of-group-by-and-having-clause) [Clause in sql](https://www.mindstick.com/interview/23311/define-over-clause-in-sql-server) [server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over) please help me.

## Replies

### Reply by Anonymous User

[Group](https://yourviews.mindstick.com/view/81323/adani-green-energy-group-bags-world-s-biggest-solar-bid) By clause is used for grouping the records of the database table(s).This clause creates a single row for each group and this process is called aggregation. To use group by clause we have to use at least one aggregate function in Select statement. We can use group by clause without where clause.

The having clause operates only on group rows of table(s) and act as a filter like as where clause. We use [having clause](https://www.mindstick.com/forum/33706/what-is-the-difference-between-having-clause-and-group-by-statement-in-sql-server) to filter data that we get from group by clause. To use having clause we need to use group by clause first.

```
SELECT emp_name, SUM(Emp_sal) AS 'salary'FROM EmployeeGROUP BY emp_nameHAVING SUM(Emp_sal) >5000
```

![Use of Group by and Having Clause in Sql Server](https://www.mindstick.com/mindstickforums/c9ccd239-9255-4e6c-90e9-19417ba2f0f4/images/78790559-3661-490c-8880-edfbd1e8b896.png)


---

Original Source: https://www.mindstick.com/forum/33663/use-of-group-by-and-having-clause-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
