sorting tables in visualforce

A List of records returned by select query can be sorted using order by clause. The field with which the resulting list be sorted should be specified after the order by clause.
We can specify whether we want a ascending sorting or a descending sorting. If the ascending or descending is not specified then the query sorts in ascending order of the specified field.
For ascending just use the keyword "'ASC" and for descending use the keyword "DESC"
1. List<Contact> conList = [select id,name,email from contact order by name desc];
2. List<account> accList = [Select id,name,accountnumber from account order by name asc] is same as below 
3.List<account> accList = [Select id,name,accountnumber from account order by name]
Here's an example that sorts a table showing 5 account records. Button sorts the table depending on the field selected for sorting

Visualforce Page


  1. can you tell me how to short table data on the bases of inner query in parent-child query

  2. I know this an old post, but I am trying to get this to work for a Tasks related list on Account Page Layout. Can you help me with this?