Group By and Where Clause
What is difference between Group by and where clause?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Sep 26, 2012, 12:22 AM
Rajeev KumarPosted Feb 27, 2023, 7:13 AM
Group by and where clause are used for Fetch the data with filtering.Firstly Where execute and after that Group By Clause.
WHERE: The WHERE clause is executed to filter out records that do not meet the constraints and The GROUP BY clause is executed to group the data based on the values in one or more columns.
Shivanand ArurPosted Sep 26, 2012, 1:18 AM
Let me give you an example for your question... Suppose we have a table something like this...
Table Name: Employee
Columns:
Emp_ID Emp_Name Emp_City
01 Deepak Mumbai
02 Shiv Delhi
03 Ramesh Mumbai
04 Satyapriya Kolkata
1) Where Clause: Suppose you want the result of employee staying in Delhi. So in that case you will use a where clause to put a condition in your query to get the desired result. You will write it this way.
"Select * from Employee where Emp_City = 'Delhi'"
This will give you the following result.
Result:
Emp_ID Emp_Name Emp_City
02 Shiv Delhi
2) Group By Clause: Suppose you want an aggregate result of the employees who stay only in Mumbai, then you can use the Group By Clause.
"Select Count(Emp_ID) as Total Employees , Emp_City from Employee Group By Emp_City"
This will give you the following result.
Result:
Total Employees Emp_City
1 Delhi
1 Kolkata
2 Mumbai
Please check out these links to know more about Group By and Where Clause.
For Group By Clause
http://www.techonthenet.com/sql/group_by.php
http://weblogs.sqlteam.com/jeffs/archive/2005/12/14/8546.aspx
http://www.1keydata.com/sql/sqlgroupby.html
For Where Clause
http://www.1keydata.com/sql/sqlwhere.html
Hope this will help you...
PLEASE MARK THE ANSWER AS ACCEPTED IF IT HELPED YOU
THANK YOU!!!
Santhosh Kumar JayaramanPosted Sep 26, 2012, 12:56 AM
WHere- It will check the condition or matches with individual rows.
Group by and Having- When we use having together with group by it will fetch group of records satisfying conditions