What is the Difference between GROUP and ORDER BY

What is the Difference between GROUP and ORDER BY

The GROUP and ORDER BY clauses are both used to organize data. But if we are talking about the difference between GROUP and ORDER BY clauses.
So we can say :
The ORDER BY clause’s use to sort the query result by specific columns.
The GROUP BY clause’s use to summarize unique combinations of columns values.

GROUP BY CLAUSE

GROUP BY is used in conjunction with the aggregate functions to group the result-set by one or more columns. Aggregate function in the SELECT list, like COUNT(), SUM(), MIN(), MAX(), AVG() etc.

Lets try understanding using example.

TABLE:
ID NAME
1  hari
2  shiv
3  laxmi
4  hari

Mysql_query(“SELECT Count(ID), NAME FROM TABLE GROUP BY NAME”);

Result :
1 shiv
1 laxmi 
2 hari

In This example we are applying GROUP BY Clause on name, in name field hari name repeat two time.

ORDER BY CLAUSE

ORDER BY is used for changing the order in which records are returned according to specified column. In other hand we can say ORDER BY Clause use to sort the data in ascending or descending order.

Lets try understanding using example.

TABLE:
ID NAME
1  hari
2  shiv
3  laxmi
4  hari

Mysql_query(“SELECT * FROM TABLE ORDER BY NAME”);

Result :
ID NAME
1  hari
4  hari
3  laxmi
2  shiv

In This example we are applying ORDER BY Clause on name, ORDER BY Clause applying sorting on name field and return result in a acceding order.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts: You may like

All Full Forms Related to Database

comma separated values in mysql query

SQL statement to retrieve names beginning with A

Php pdo prepared statements select insert update queries

php pdo queries statements select insert update delete

Selecting data from more than 2 tables or three tables using mysql joining

php mysqli conneection object oriented

Short Upcoming Birthday MySQL Queries

Simple ajax php mysql login page

Easy simple pagination using php and mysql

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Free online tool to download Instagram videos, photos and save Instagram videos, photos to your device. It's free & easy to use.

Download Now

CURRENCY CONVERTER

Our real time currency converter calculator will convert your money based on current values from around the world. It's free & easy to use.

Convert Now

ROBOST.TXT GEN.

Create robots txt file that help search engines to crawling and indexing your site with help of our free online Robots.txt Generator tool.

Create Now

HTML MINIFIER

Free online tool to minify or compress html code and reduce the size of html code in few clicks. It's free & easy to use.

Minify Now

CSS MINIFIER

Free online tool to minify or compress css code and reduce the size of css code in few clicks. It's free & easy to use.

Minify Now

JAVASCRIPT MINIFIER

Free online tool to minify or compress javascript code and reduce the size of javascript code in few clicks. It's free & easy to use.

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.