MySQL Order By - MySQL - Phptpoint.com

MySQL Order By

PHP Summer Training/Internship with 2 Live Projects in Noida Fee is only 5500/-Click here to Book Your Seat.

/ins>

How to use MySQL Order By

The ORDER BY is a keyword which is used to sort the results based on one or more columns.
by default it sorts the result set in ascending order . if we want to sort the results in descending order we use DESC keyword. for ascending order we use ASC keyword.

Syntax

Retrieve all records from empInfo table in ascending order.

Output :

Emp_idNameEmailMobile
1deveshdevesh@gmail.com9910099100
2deepakdeepak@gmail.com9210053520
3raviravi@gmail.com9810098100

In the above example there is a empInfo table the data is retrived in ascending order based on emp_id
the fetched data is stored in the val variable and results are displayed in tabular form.

Retrieve all records from empInfo table in descending order.

Output :

Emp_idNameEmailMobile
3raviravi@gmail.com9810098100
2deepakdeepak@gmail.com9210053520
1deveshdevesh@gmail.com9910099100

In the above example first we create connection with the database and data is retrived in descending order by using DESC keyword the fetched data is stored in the val variable and results are displayed in tabular form.

Latest Trending Technologies