![sorting 0110](../figures/sorting-0110.png)
85. Sorting the Records
In this chapter we will learn how to sort records with the ExtSort component.
This chapter builds on the graph from Creating a Transformation Graph.
Adding ExtSort
![sorting 0110](../figures/sorting-0110.png)
Setting Up the ExtSort Component
Double-click the ExtSort component.
Click the Sort key row in the component editor. A button appears in this row.
![extsort 010](../figures/extsort_010.png)
Use the button to open Sort Key dialog:
![extsort 020](../figures/extsort_020.png)
Select the key that will be used for sorting the incoming records.
Drag the Salary
item from the Fields pane and drop it to the Sort key pane.
Do the same with LastName
and FirstName
items in this order.
![extsort 028](../figures/extsort_028.png)
Click the cell in the Order column right from the salary
item and select Descending
instead of Ascending
.
This way you have selected the fields according to which the incoming records should be sorted.
The records will be sorted according to the salary
field values in descending order.
Records with same salary
will be sorted according to lname
in ascending order.
Records the same salary
and lname
will be sorted according to fname
in ascending order.
Thus, any person with salary
of 25000
would be sent out after any other person with salary of 28000
.
And, within the same salary
, any Brown
would be sent out through the output port before any Smith
.
And again, within the same salary, any John Smith
would be sent out before any Peter Smith
.
In other words, the fields located higher in the Key parts pane have higher sorting priority.
![extsort 030](../figures/extsort_030.png)
After clicking OK, a sequence of field names separated by semicolon will appear in the component editor:
![extsort 040](../figures/extsort_040.png)
Run the graph and see the results.
You can see that all salaries are sorted in descending order.
Note that within the same salary of 30000 both Browns
lies above George Smith
and that Albert Brown
lies higher than Peter Brown
.