# Sort

## Content

The **Sort** transformation arranges the input data in ascending or descending order. The **DataEngine** library allows you to sort **Base Tables** (data engine tables which contain the imported data) and the query result tables (result of a query) easily.
The first step to sort a base table or a query result table is to retrieve its collection of rows using the [GetTableData](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.Workspace.GetTableData.html) method or [GetQueryData](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.Workspace.GetQueryData.html) methods of the [Workspace](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.Workspace.html) class respectively. These methods return an instance of the [IDataList](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine/C1.DataEngine.IDataList.html) interface.
Once the data of the base table or query result table is retrieved, you can easily sort it using the [Sort](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine.Api/C1.DataEngine.DataList.Sort.html) method of the [DataList](/componentone/api/services/online-dataengine/dotnet-standard-api/C1.DataEngine.Api/C1.DataEngine.DataList.html) class. The **Sort** method accepts the following three parameters: the collection of rows (which is an instance of the **IDataList** interface), name of the column to sort and the sort direction (true for ascending and false for descending).
The following example demonstrates how the query result table ‘**SalesByCategory**’ can be sorted in descending order by the column ‘**Sales**’.

```csharp
// Output query results in CSV format to the console
IDataList sales = workspace.GetQueryData("SalesByCountry");
DataList.Sort(sales, "Sales", false); // Sort by Sales value in descending order
```