This tip demonstrates how to sort data according to the values of two columns.
In the following example we have a table called “EVENTS” which has 4 fieldsSrNo, EventName, StartDate and EndDate
The requirement is that the events should be sorted and shown according to the latest date (started or ended) on it.
Based on the above given dates,the correct order of output will be :
Because the latest action is done on Event3 (it ended on 21/03/2010). Before this the action is last done on Event2 (it started on 20/03/2010) and earlier still on Event1 ( it ended on 18/03/2010).
Here we need to sort the output both according to the start date and end date depending on their values.
To fetch data from EVENTS table we may write any one of the following queries