Including Mental Health Support in Project Delivery, 14 May.pdf
Order by
1. Order By
With the help of Order By command we can arrange
the records our table in ascending or descending
order.
This command is used with the select command.
Syntax :-
Select column name(*) from table name
Order by column name ASC/DESC;
1. Select * from student
Order by name;
2. Select * from student
Order by marks ASC;
Ordering DATA on Multiple column
2. To order the result set on multiple column you can
specify the multiple column name in ORDER BY
command along with desired sort order.
Example ;-
Select * from student
Order by section ASC,Marks DESC;
Ordering Data on the basis of an Expression
Example ;-
1. Select name,marks,marks+10 from students;
2. Select name,marks,marks+10 from students
Order by marks+10 DESC;
CUSTOM SORT ORDER
You have a column where you want to arrange data as
per your own specified order.
Example :- if there is column called project that store
the status of project made by the students.
3. Name Project
Ali Evaluated
amit Evaluated
Aryan Assigned
Dilip Assigned
Kavita Pending
Neha Submitted
Rahil Evaluated
Ruhani Pending
Simran Submitted
Simran Pending
Sohil Submitted
Sumit Submitted
Select * from student
Order by name;
Now to order the above table as per the mentioned
order above i.e. as per Project field having values in this
order:-
1.Evaluated
2.Pending
4. 3.Submitted
4.Assigned
Syntax ;-
Select * from tablename
Order by field(columnanme,values specifying order);
Example :-
Select * from student
Order by
field(project,’Evaluated’,’Pending’,’Submitted’,’Assigned’);
Output :-
Name project