SQL ORDER BY Clausecan't see properly

ORDER BY Clause is use arrange columns either ascending or descending order.

syntax

SELECT COLUMN 1,COLUMN2 FROM TABLE_NAME ORDER BY Column2,Column1

Demo Database (Customer Table)

CustomerID CustomerName ContactName Address City PostalCode Country
1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Germany
2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitucion 2222 Mexico D.F. 05021 Mexico
3 Antonio Moreno Taqueria Antonio Moreno Mataderos 2312 Mexico D.F. 05023 Mexico

example

SELECT * FROM Customers ORDER BY Country;

Above Statement select all the data Order the country column from Customers..

CustomerID CustomerName ContactName Address City PostalCode Country
12 Cactus Comidas para llevar Patricio Simpson Cerrito 333 Buenos Aires 1010 Argentina
48 Rancho grande Sergio Gutierrez Av. del Libertador 900 Buenos Aires 1010 Argentina
20 Ernst Handel Roland Mendel Kirchgasse 6 Graz 8010 Austria
60 Supremes delices Pascale Cartrain Boulevard Tirou, 255 Charleroi B-6000 Belgium

ORDER BY using DESC

example

SELECT * FROM Customers ORDER BY Country DESC;

Above Statement select all the data Order the country column descending order from Customers..

CustomerID CustomerName ContactName Address City PostalCode Country
33 GROSELLA-Restaurante Manuel Pereira 5a Ave. Los Palos Grandes Caracas 1081 Venezuela
35 HILARION-Abastos Carlos Hernandez Carrera 22 con Ave. Carlos Soublette #8-35 San Cristobal 5022 Venezuela
32 Great Lakes Food Market Howard Snyder 2732 Baker Blvd. Eugene 97403 USA
36 Hungry Coyote Import Store Yoshi Latimer City Center Plaza 516 Main St. Elgin 97827 USA

ORDER BY on Multiple Columns

example

SELECT * FROM Customers ORDER BY Country,CustomerName;

Above Statement select all the data Order both the column Country and CustomerName from Customers..

CustomerID CustomerName ContactName Address City PostalCode Country
12 Cactus Comidas para llevar Patricio Simpson Cerrito 333 Buenos Aires 1010 Argentina
48 Rancho grande Sergio Gutierrez Av. del Libertador 900 Buenos Aires 1010 Argentina
20 Ernst Handel Roland Mendel Kirchgasse 6 Graz 8010 Austria
60 Supremes delices Pascale Cartrain Boulevard Tirou, 255 Charleroi B-6000 Belgium

For More References:

MySQL DML

Oracle DML

Loading Questions

If you are facing any issue like can not see video so please login into Google with email what you forwarded to us Google Login or mail to administrator qatraining@infotek-solutions.com