MySQL Order By

MySQL Order By


In this tutorial we have to learn MySQLI ORDER BY statement .By using SELECT command results are returened in the same order the records where added into the database.this is bydefault sorting order. in this tutorial we can see sorting our query results.

Sorting can be single or more than one column in a table.The MySQL ORDER BY clause is used to sort the query result sets in either ascending or descending order.ORDER BY clause sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.

Syntax :

SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC 

We can easly understand with given below example 

Example (MySQLi Object-oriented) :

output :

Explain code : In this  example we set up the SQL query that selects the id, firstname and lastname columns from the Employee table ORDER BY  firstname". where condtion order by sorting in by default ascending order  then show it on output as we can see.

Example (MySQLi Procedural) :

Output :

ORDER BY aslo using HTML TABLE  for Example :

Output :