ORDER BY Syntax in Select Query can be used to arrange the data in Ascending or Descending order.
Example Table : For your reference
table_name
Column_name1 | Column_name2 | Column_name3 | Column_name4 |
1 | Male | articles | Sam |
2 | Female | database | Sam |
3 | Male | coding | Jam |
4 | Male | coding | Kam |
5 | Female | coding | Jam |
Table Name is : table_name
ASCENDING ORDER
Query : "SELECT * from table_name ORDER BY Column_name3"
or
Query : "SELECT * from table_name ORDER BY Column_name3 ASC"
If you execute the above query then Column_name3 data will be sorted in ascending order
Column_name1 | Column_name2 | Column_name3 | Column_name4 |
1 | Male | articles | Sam |
3 | Male | coding | Jam |
4 | Male | coding | Kam |
5 | Female | coding | Jam |
2 | Female | Database | Sam |
DESCENDING ORDER
Query : "SELECT * from table_name ORDER BY Column_name3 DESC"
Query : "SELECT * from table_name ORDER BY Column_name3 DESC"
If you execute the above query then Column_name3 data will be sorted in descending order
table_name
Column_name1 | Column_name2 | Column_name3 | Column_name4 |
2 | Female | Database | Sam |
5 | Female | coding | Jam |
4 | Male | coding | Kam |
3 | Male | coding | Jam |
1 | Male | articles | Sam |
Comments
Post a Comment