- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference Between Group By and Order By in SQL
In this post, we will understand the difference between group by and order by in SQL.
It is used to group the rows which have the same value.
It can be used in CREATE VIEW statement.
In select statement, it has to be used before the ‘ORDER BY’ keyword.
Attribute can’t be in a ‘GROUP BY’ statement when it is under aggregate function.
The tuples are grouped based on how similar the attribute values of the tuples are.
It controls the presentation of the tuples/rows.
It doesn’t use the ‘CREATE VIEW’ statement.
The result-set is sorted in ascending or descending order.
It is used after the ‘group by’ keyword.
The attribute can be under an aggregate function.
It controls the presentation of columns.
Following is the syntax of Group By and Order By in a single query −
SELECT column1, column2 FROM table_name WHERE [ conditions ] GROUP BY column1, column2 ORDER BY column1, column2
- How to use order by, group by in c#?
- Example of SQL query describing COUNT function and GROUP BY
- Difference between SQL and PL/SQL
- Difference Between SQL and T-SQL
- Difference between Call by Value and Call by Reference
- Difference between Static SQL and Dynamic SQL
- Difference Between T-SQL and PL-SQL
- How to ORDER BY FIELD with GROUP BY in a single MySQL query?
- Difference between SQL and NoSQL
- GROUP BY the number of rows returned by GROUP BY in MySQL?
- SQL query describing usage of SUM aggregate function and GROUP-BY with HAVING
- Listing all rows by group with MySQL GROUP BY?
- How can group functions be used in ORDER BY clause?
- How to display records having sum between a specific range using GROUP BY, HAVING and ORDER BY in a single MySQL query?
- Difference between MySQL and SQL Server