Skip to main content
Workforce LibreTexts

7.3: Sorting Queries

  • Page ID
    14260
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Sorting in Access is the process of rearranging records in a specific order. Sorting data can create a significant impact on the usability of Access queries and reports. Sorting can occur before or after executing a query. In the datasheet view, a query can be sorted after running the query by using the Sort Ascending and Sort Descending buttons in the Sort & Filter group of the Home tab.

    Sort buttons
    Sort buttons

    To create more complex sorting criteria, use the Query Design window to create multi-field sorts.

    Sorting Rules
    Sorting Rules

    Multi-field sorting requires the use of primary, secondary and potentially, tertiary sorting fields. Using Access’ Query Design View, fields can be arranged in any order to accommodate the desired order. It is important to comply with the sorting rules inherent with the various data types of each field (see table to the left). Access will sort the fields in the Query Design from left to right. However, this can by manipulated by adding duplicate fields to the grid, specifically for sorting purposes. The key to this strategy is to utilize the Show checkbox for these sort-only fields. Clearing the Show checkbox will prevent these fields from displaying the Datasheet results, but their sorting mission will still be accomplished! Using Query Design also affords the ability to sort one field in Ascending order and another in Descending order in the same sort process.

    In the example below, the goal is to sort the records primarily by Last Name. However, some records might share the same Last Name. Therefore, if there are duplicates, the First Name field will serve as the secondary sort criteria. Furthermore, it is desired that the results set display the records with the First Name field to the left of the Last Name field. This necessitates the use of a duplicate First Name field that will only be used for sorting purposes. Also notice that the Show checkbox is cleared for this duplicate field, so as not to confuse the layout of the results set. Hiding a field, by clearing the Show checkbox. can also be used for applying Criteria restrictions on a field that is not desired to be displayed in the results set, but is needed to narrow the results. This is popular with the sensitive data, like Salary or Credit Limits.

    Access Sorting
    Access Sorting

     


    This page titled 7.3: Sorting Queries is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Marcus Lacher (Minnesota Libraries Publishing Project) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?