When sorting data on multiple fields in the query designer which field takes precedence in the sort?

  • Now, open the table in Datasheet view.

  • On the Home tab, in the Sort & Filter group, click Advanced and then click Advanced Filter/Sort on the shortcut menu.

  • Add the fields you want, such as FirstName, LastName, and Title, to the grid.

  • Right-click the Field row in the first blank column, click Zoom, and then type the following expression:

    IIf ([Title] = "Vice President, Sales", 1, IIf ([Title] = "Sales Manager", 2, IIf ([Title] = "Sales Representative", 3, IIf ([Title] = "Inside Sales Coordinator", 4, 5))))

    Title is the name of the field that contains the values that are being ranked. The values enclosed in quotation marks are the individual values stored in the field. The numeric value that follows is the rank assigned to it. The preceding expression assigns ranks 1 through 4 to four different titles, and assigns rank 5 to all others. When you perform the sort, the titles not mentioned in this expression are assigned the same rank (5).

  • In the Sort row for the column containing the expression, click Ascending.

  • On the Home tab, in the Sort & Filter group, click Toggle Filter.

    The IIf function returns the numeric value that corresponds to the value in the Title field. For example, if the value in the Title field is Sales Manager, the number assigned is 2. If there is a value in the Title field not listed as an argument in the function — for example, District Coordinator — it is assigned the number 5. The query then sorts these numbers in ascending order.

  • Sorting records in a table allows you to better understand the data that you are working with. You can discover the largest and smallest values or perhaps the most and least significant features in the layer. Sorting is also an efficient means for organizing your data in alphabetical or sequential order.

    To sort up to four fields at once

    1. Right-click a field name and click Advanced Sorting.
    2. Click the Sort by arrow and click the first field by which you want to sort.
    3. Click Ascending or Descending to choose the sort order.
    4. Click the Then sort by arrow, click the next field, then choose a sort order.
    5. Click up to two more fields and their sort orders. Choose (none) if you don't want to sort the fields at that level.
    6. Click OK.

    You can press SHIFT and double-click a field name or CTRL+SHIFT+S as a shortcut to opening the Advanced Table Sorting dialog box.

    To select all adjacent columns, place the pointer over the heading of the leftmost column, then click and hold while dragging to the right.

    To sort more than four records at once, use the CTRL key to select multiple fields, right-click, then choose to sort in ascending or descending order. The fields are sorted in the order you click them in the table.

    When sorting data on multiple fields in the query designer which field takes precedence in the sort?

    Tables normally display records in the order they were entered. Instead of working with a table's jumbled record order, you can create a simple query that sorts the table information and presents it in an ordered, easy-to-read display. You can sort records alphabetically, numerically, or chronologically (by date) in ascending (A to Z) or descending (Z to A) order. You can also sort by multiple fieldsfor example, you could sort by LastName and then by FirstName. This lesson will show you how you can use a query to sort information in a table.

    1. In the Database window, double-click Create query from Design view. Click Employees, click Add, and then click Close.

      Notice that an asterisk (*) appears at the top of the Employees field list. Selecting a table's asterisk (*) in a query selects all of its fields at once.

    2. Double-click the asterisk (*) in the Employees field list.

      Access adds the asterisk to the design grid. Now you have to add the fields you want to use to sort the query.

    3. Double-click LastName and FirstName in the Employees field list to add them to the design grid.

      You are going to use the LastName and FirstName fields to sort the query. To sort a query, click the Sort row for the field you want to use to sort the query and select either Ascending or Descending.

    4. Click in the LastName field's Sort box. Click the list arrow and select Ascending from the list. Repeat this step for the FirstName field.

      The LastName and FirstName fields will already be displayed with all the other fields in the table because you added the asterisk (*) to the design grid. Because you don't want the LastName and FirstName fields to appear twice, you can uncheck their "Show" boxes.

    5. Uncheck the Show box for the LastName and FirstName fields.

      Your query should look like figure. The query will still use the LastName and FirstName fields for sorting purposes, but it won't display these field names in the query results.

    6. Save your query as AZ Query and then click the Run button on the toolbar to view the results. Close the query when you're finished.

    TO SORT A QUERY USING MULTIPLE FIELDS:

    1. OPEN/DISPLAY THE QUERY IN DESIGN VIEW.

    2. IF NECESSARY, ADD THE FIELD YOU WANT TO USE TO SORT THE QUERY TO THE DESIGN GRID.

    3. CLICK THE SORT BOX LIST ARROW FOR THE FIRST FIELD YOU WANT TO USE TO SORT THE QUERY, THEN SELECT A SORT ORDER.

    4. REPEAT STEPS 2-3 FOR EACH ADDITIONAL FIELD YOU WANT TO USE TO SORT THE QUERY, BEARING IN MIND THAT THE FIELDS WILL BE SORTED FROM LEFT TO RIGHT.