GROUP BY vs. ORDER BY Comparison Chart
The following comparison chart explains their main differences in a quick manner:
| SN | GROUP BY | ORDER BY |
|---|---|---|
| 1. | It is used to group the rows that have the same values. | It sorts the result set either in ascending or descending order. |
| 2. | It may be allowed in CREATE VIEW statement. | It is not allowed in CREATE VIEW statement |
| 3. | It controls the presentation of rows. | It controls the presentation of columns. |
| 4. | The attribute cannot be under aggregate function under GROUP BY statement. | The attribute can be under aggregate function under ORDER BY statement. |
| 5. | It is always used before the ORDER BY clause in the SELECT statement. | It is always used after the GROUP BY clause in the SELECT statement. |
| 6. | It is mandatory to use aggregate functions in the GROUP BY. | It's not mandatory to use aggregate functions in the ORDER BY. |
| 7. | Here, the grouping is done based on the similarity among the row's attribute values. | Here, the result-set is sorted based on the column's attribute values, either ascending or descending order. |
WHERE vs. HAVING Comparison Chart
| Comparison Basis | WHERE Clause | HAVING Clause |
|---|---|---|
| Definition | It is used to perform filtration on individual rows. | It is used to perform filtration on groups. |
| Basic | It is implemented in row operations. | It is implemented in column operations. |
| Data fetching | The WHERE clause fetches the specific data from particular rows based on the specified condition | The HAVING clause first fetches the complete data. It then separates them according to the given condition. |
| Aggregate Functions | The WHERE clause does not allow to work with aggregate functions. | The HAVING clause can work with aggregate functions. |
| Act as | The WHERE clause acts as a pre-filter. | The HAVING clause acts as a post-filter. |
| Used with | We can use the WHERE clause with the SELECT, UPDATE, and DELETE statements. | The HAVING clause can only use with the SELECT statement. |
| GROUP BY | The GROUP BY clause comes after the WHERE clause. | The GROUP BY clause comes before the HAVING clause. |