AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
HTML Tutorial

SQL mysql order by columns, by date, by asc, by desc, random with PHP


The SQL ORDER BY is used to sort the data in ascending or descending order from database, based on one or more columns.
The ORDER BY keyword sorts the records in ascending order by defaultin database. If you want to sort the records in descending order, use the DESC keyword.

SQL mysql order by columns asc or desc - example


Syntax: The basic syntax of the mysqli order by;
SELECT col1, col2, col3, ...
FROM name_table
ORDER BY col1, col2, col3,... ASC|DESC;


Example 1: Your database named as Customers
ID Name Contact Address City
1

Jones Cruise Ana Maria Will Str. 57 Paris
2 Robert Caine Ana Trujillo Avda. Larga 24 Roma
3 Brad Bale Antonio mauro Mataderos 19 Madrid

The following -SQL order by - select all - Name -from "Customers" table, sorted by the "City" column:
SELECT * FROM Name ORDER BY City;

The result
ID Name Contact Address City
3 Brad Bale Antonio mauro Mataderos 19 Madrid
1

Jones Cruise Ana Maria Will Str. 57 Paris
2 Robert Caine Ana Trujillo Avda. Larga 24 Roma
Note: The ORDER BY keyword sorts the records in ascending order by default

SQL ORDER BY DESC Example - How to create

The following SQL statement selects all Name from the "Customers" table, sorted DESCENDING by the "City" column:

Example 2: welcome.php
SELECT * FROM Name
ORDER BY City DESC;

The results -
ID Name Contact Address City
2 Robert Caine Ana Trujillo Avda. Larga 24 Roma
1

Jones Cruise Ana Maria Will Str. 57 Paris
3 Brad Bale Antonio mauro Mataderos 19 Madrid


mysql order by, mysql select query php, mysql order by 2 columns, by date, by multiple columns, by random, by asc, by desc
SQL mysql order by columns, by date, by asc, by desc, random with PHP - sql tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home - Database
SQL - Database
SQL Syntax
SQL Select Data
SQL Insert Data
SQL Update
SQL Delete Row
PHP mysqli_query()
SQL order
SQL Create Database
SQL Display Data
SQL Count()
SQL mysqli_connect
SQL create table
SQL Where And & Or
SQL like Syntax
SQL Between Operator
SQL IN Operator
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.