There are two commands commonly used in database querys and that are also indispensable in MySQL, GROUP BY and ORDER BY help you when you need sort and group data and now we will understand better how they work.


This command is used practically to sort a query from a column. This can be alphabetical ordering for columns of type varchar, for example, or numeric for columns of type integer. Using the following syntax you can use it.

SELECT [fiels] FROM [table] ORDER BY [Column]

As a practical example we sort a query the Products table.

SELECT Cod, Name

FROM product


In the above query will return all records from the Products table sorted by the field that stores the code (Cod).


The command GROUP BY can be used as a kind of ordering, but its main function is to group the data so that it is possible to analyze the joint information of a particular block of information. For example, you can examine the records of a table by grouping them around town. Check the syntax of this command below.

SELECT [fields] FROM [table] GROUP BY [column]

Using the same example given above we group the data from a table of records from the city of each of the records.

SELECT Name, Phone

FROM Register


Thus will display the name and number of each record of the table records grouped by city registered.


Queries are essential in everyday life of any programmer, so to understand the functioning of these two commands is something essential. In addition, MySQL has become very common in environments for development, especially those using PHP. Qeer know more? Then click the link above to learn more about MySQL and PHP.

By ,

September 5, 2013


You might also like…

5 reasons you can’t miss a Black Friday Scriptcase!

This November we bring you the biggest and most important discounts of the year! And do you know wh...

Taking a look at Scriptcase version 9.7

After the big Scriptcase 9.7 presentation event, we have a new version of Scriptcase for download, ...

October Newsletter

Follow the latest news for the month of October! Webinars, blog posts, videos, and more. WEB...

You might also like…

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at Learn more about our Privacy Police.