SQL Order by Clause

free php tutorials, php classes, php utilities, free tools

The ORDER BY statement orders the returned values by the specified column(s) in Ascending or descending. The ORDER BY keyword sort the records in ascending order by default.

The Syntax

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

The Example of AND Operator

select * from tutorials order by author

this will retrieve following result.

ID Category Author Tutorial
3 Ajax Andrew what is ajax
5 C++ Andrew C++ Basics
1 PHP Hassan what is php
2 MySql James what is sql
4 ASP James ASP Introduction

ORDER BY DESC Example

Now we want to select all the author from the table, however, we want to sort the tutorials descending by their author.

select * from tutorials order by author desc

this will retrieve following result.

ID Category Author Tutorial
2 MySql James what is sql
4 ASP James ASP Introduction
1 PHP Hassan what is php
3 Ajax Andrew what is ajax
5 C++ Andrew C++ Basics

Bookmark This Page