Order MySQL results

In this tutorial, you'll learn how to sort MySQL result. You can sort MySQL result by ascending, descending and random MySQL result.

Overview

You can order MySQL results using "ORDER BY"

1. ORDER BY column_name ASC
2. ORDER BY column_name DESC
3. ORDER BY RAND().

1. ORDER BY column_name ASC is order by ascending.
2. ORDER BY column_name DESC is order results by descending.
3. ORDE BY RAND() is order results by random.

If you're not set this up the default is order results by ascending.

Syntax

"SELECT column_name FROM table_name ORDER BY column_name ASC";
or
"SELECT column_name FROM table_name";
- This will select the records from mysql by ascending (ascending is the default value).


"SELECT
column_name FROM table_name ORDER BY column_name DESC";
- This will select the records from mysql by descending


"SELECT
column_name FROM table_name ORDER BY RAND()";
- This will select the records from mysql by random

Example Order by Ascending

order mysql result by ascending
The records were sorted by id by ascending

Example Order by Descending

order mysql result by descending
The records were sorted by id by descending

Example Order by Random

order mysql result by random
The records were sorted by random

Similar Post
Introduction to MySQL database

Introduction to MySQL database

MySql is a powerful database. It's very good and free of charge. Many developers in the world selected mysql and php for developing their website.
Update multiple rows in mysql

Update multiple rows in mysql

This tutorial will show you how to update multiple rows with one time submittion. Easy and simple code teach you step by step.