All for Joomla All for Webmasters

SQL ORDER BY CLAUSE WITH ASCENDING ORDER

This statement is used to sort data in ascending order. If you miss the ASC attribute, SQL ORDER BY query takes ascending order by default.

Let?s take an example of supplier

  1. SELECT supplier_city
  2. FROM suppliers
  3. WHERE supplier_name = ‘IBM’
  4. ORDER BY supplier_city;

Let us take a CUSTOMERS table having the following records:

ID NAME AGE ADDRESS SALARY
1 Himani gupta 21 Modinagar 22000
2 Shiva tiwari 22 Bhopal 21000
3 Ajeet bhargav 45 Meerut 65000
4 Ritesh yadav 36 Azamgarh 26000
5 Balwant singh 45 Varanasi 36000
6 Mahesh sharma 26 Mathura 22000

This is an example to sort the result in ascending order by NAME and SALARY.

  1. SELECT * FROM CUSTOMERS
  2. ORDER BY NAME, SALARY;

This would produce the following result.

ID NAME AGE ADDRESS SALARY
3 Ajeet bhargav 45 Meerut 65000
5 Balwant singh 45 Varanasi 36000
1 Himani gupta 21 Modinagar 22000
6 Mahesh sharma 26 Mathura 22000
4 Ritesh yadav 36 Azamgarh 26000
2 Shiva tiwari 22 Bhopal 21000
PinIt
submit to reddit

Leave a Reply

Top