Difference Between Where and Group By Clause
Where Clause |
Group by Clause |
---|---|
Where Clause is generally used to filter the rows from a table based on a specific condition. |
Group by clause is used to group rows by one or more columns. |
It does not involve an aggregate function. |
It involves aggregations functions like SUM(), AVG(), COUNT(),MAX() etc. |
Where clause is used with select, update, and with delete statements. |
It is used only with select statements. |
Its affected individual rows. |
It affects the whole group of rows to perform aggregate functions. |
It does not involve having clause. | It involves having clause. |
Difference between Where and Group By
Where and Group By clauses are used to filter rows returned by the query based on the condition. In this article, we will discuss Where Clause and Group By Clause as well as we will discuss Differences Between Where and Group By Clause. Before proceeding to that, let’s first discuss the Use Case Statement.
Use Case: Suppose some sales company wants to get a list of Customers who bought some number of items last year so that they can sell more stuff to them this year. There is a table called SalesOrder with columns CustomerId, SalesOrderId, Order_Date, OrderNumber, OrderItem, UnitPrice, and OrderQty Now we need to get the customers who made orders last year i.e. 2017.