What is the difference between GROUP BY and ORDER BY in
Sql?

Answer Posted / niraj kumar

To sort a result, use an ORDER BY clause.
The most general way to satisfy a GROUP BY clause is to
scan the whole table and create a new temporary table where
all rows from each group are consecutive, and then use this
temporary table to discover groups and apply aggregate
functions (if any).
ORDER BY [col1],[col2],...[coln]; Tells DBMS according to
what columns it should sort the result. If two rows will
hawe the same value in col1 it will try to sort them
according to col2 and so on.
GROUP BY [col1],[col2],...[coln]; Tells DBMS to group
(aggregate) results with same value of column col1. You can
use COUNT(col1), SUM(col1), AVG(col1) with it, if you want
to count all items in group, sum all values or view
average.

Is This Answer Correct ?    24 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is database migration in mysql?

526


Where is mysql used?

524


How do I edit a table in mysql workbench?

445


How do I show users in mysql?

519


How does mysql store dates?

499






How to dump one database for backup.

501


Is mongodb faster than mysql?

508


Why should I learn mysql?

490


What are the two types of queries?

451


How do I start mysql?

497


What is the function of mysqldump?

578


Is mysqli deprecated?

502


What is pdo in php mysql?

506


How do I view a mysql database?

483


Why myisam is faster than innodb?

492