8.5 Sorting records
Sorting is the process of arranging records into a particular order. You are able to arrange records into alphabetical, numerical or chronological (date) orders.
You can sort data on one field only or on multiple fields. For example, you could list the Pizza Palace database in location order and within each location list the employees in alphabetical order by the names.
Databases exercise 3
Single field sorting
Skills practised
- One field sort
- Multiple fields sort
- Sort ascending
- Sort descending
Sorting can be quickly carried out on single fields.
- In Microsoft Access open the
EMPLOYEE PAY QUERYand:- Click in a
LOCATIONvalue then click on theASCENDINGicon in the Home tab of the ribbon and all the records are rearranged so that they are inLOCATIONorder. - Click on a
PAYvalue then click on theDESCENDINGicon in the Home tab of the ribbon and all the records are rearranged so that the highest incomes are listed first down to the lowest incomes. - Click on the
REMOVE SORTicon in the ribbon to return the records to their original order.
- Click in a
- In FileMaker Pro:
- Click on the
LOCATIONfield label at the top of the table and the records are rearranged so that they are displayed alphabetically in location order. - Click on the
PAYheading and all the records are rearranged so that the lowest incomes are listed first down to the highest incomes. - Click on the
PAYheading again and all the records are rearranged in descending order. - Click on the
SORTicon in the Toolbar, selectUNSORTin theSORT RECORDSdialogue box and selectOKto return the records to their original order.
- Click on the
Multiple field sorting
More complex sorting can be carried out on multiple fields. To illustrate this the data will be sorted into LOCATION alphabetical order, within each location the LAST NAMES will be sorted into alphabetical order and, if any last names are the same, the FIRST NAMES will be sorted into alphabetical order.
- In Microsoft Access a query can be rearranged to permanently display a sort order. To do this the columns are moved in the query so that the first field to be sorted is at the left, followed by the next field to be sorted, etc.
- Click on the
VIEWicon in the ribbon to open theQUERY DESIGNview. - Click on the bar above the
LOCATIONfield then drag the column by the bar to the left ofFIRST NAME. - Click on the bar above the
LAST NAMEfield then drag the column by the bar to the left ofFIRST NAME. - Set the
SORTbox forLOCATION, LAST NAMEandFIRST NAMEtoASCENDING.
- Run the Query and the records should be grouped with the
LOCATIONStogether and within each location the names in alphabetical order. - If you don’t want a query altered, you can duplicate then make the sort changes to the duplicate, or you can create a new query.
- Click on the
- In FileMaker Pro:
- Click on the
SORTicon in the Toolbar. - Click on the
CLEAR ALLbutton to clear any fields from theSORT ORDERframe. - Move the
LOCATION, LAST NAMEandFIRST NAMEfields into theSORT ORDERframe. - If necessary a field can be selected in the
SORT ORDERframe and its order changed toDESCENDING. In this case the defaultASCENDING ORDERis applied to all the fields.
- Click on the
SORTbutton and the records should be grouped with theLOCATIONStogether and within each location the names in alphabetical order.
- Click on the