ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Software

Microsoft Access Query

Updated on March 13, 2010

Introduction

Here are some helpful tips for using the Microsoft Access query tools to manipulate database tables. We will demonstrate how to create a Select query and also how to access the SQL generated by the query designer.

First, we create a simple table to work with. If you already have a table, you can use that instead. Our table, called tPlayer, consists of a list of names, positions, uniform numbers, and salaries. Our query will extract a subset of the table information and sort it alphabetically by name.

Table Design

The table design we will use in our examples
The table design we will use in our examples

Table Data

Sample data in our table
Sample data in our table
PlayerID
PlayerName
Position
UniformNumber
Salary
1
Cheaney
Forward
40
900000
2
Graham
Guard
20
800000
3
Bailey
Guard
22
800000
4
Lindemann
Center
50
100000
5
Nover
Center
45
500000
6
Reynolds
Guard
21
500000
7
Alford
Guard
12
600000
8
Knight
Forward
25
10000
9
Gordon
Guard
2
500000
10
Jeffries
Forward
2
800000
Sample data in our table

Add the table to the query design

After creating the table in the database and the sample table, we create a new query. While the Query Wizard is useful for extremely elementary queries, we always start with the Query Designer in order to have access to the full capabilities of Microsoft Access. The query is initially empty; the first thing we do is add the Player table to the query. Refer to the figure below.

Add the table to the new query
Add the table to the new query
The query design with the table added to it
The query design with the table added to it

At this point we need a little direction. What should the query do? Since we are creating a "Select" query, the implication is that we are interested in a subset of the table data or an organized presentation of all the table data.

Let us assume for the sake of this tutorial that we are interested in a roster of all the players and their uniform numbers, sorted by player name. This is a subset of the table data since we plan to exclude salary and position. We can specify the sort order and the desired fields through the query designer. Simply double-click on the PlayerName and UniformNumber fields. Each field will be dropped in to the query grid. Refer to the following screen shot.

Add the desired fields to the query design

Two fields have been added to the query design
Two fields have been added to the query design
Sort the PlayerName column
Sort the PlayerName column

Sort the query results by Player Name

We cannot assume that the underlying table data is sorted in any particular order. Regardless of how the rows were entered into the table, always add a sort command to the query to ensure the results are sorted properly. Simply click on sort field below the desired field (in this case, PlayerName) and select Ascending or Descending.

Note that nothing we do here will affect the underlying data. A Select Query, by definition, is non-destructive. When the query executes, a snapshot of the data is presented. All the rows in the table(s) remain unchanged.

"Run" the query

Execute the query by selecting "Datasheet View"
Execute the query by selecting "Datasheet View"

View the query results

Microsoft Access uses the terminology "Datasheet View" to describe the results of running a Select Query. From the Query Design Toolbar, select Datasheet View. The query will be submitted to the database engine and the results will be presented on the screen.

Note that this is a snapshot view and it is not up-datable. It is possible to create a Select Query that is update-able, but that is beyond the scope of this tutorial.

Refer to the image below for the query results.

Datasheet View

The results of the query
The results of the query

SQL is generated by the Microsoft Access Query Tool

Behind the scenes, it's important to note that the query designer actually generates SQL (Structured Query Language). The Microsoft Access database engine actually processes the SQL rather than the query design. Experienced database designers often skip the designer tool and manually enter the SQL when creating a query.

Here is the SQL that was generated by the query we created in this tutorial:

SELECT tPlayer.PlayerName, tPlayer.UniformNumber
FROM tPlayer
ORDER BY tPlayer.PlayerName;

Accessing the SQL View of the query

The Query Designer generates SQL based on your design
The Query Designer generates SQL based on your design

Structured Query Language

The SQL generated by the Query Designer. This is the "SQL View" provided by the Query Designer.
The SQL generated by the Query Designer. This is the "SQL View" provided by the Query Designer.

Conclusion

In this tutorial we demonstrated how to create a simple "Select" query using the Microsoft Query Tool. We also explained how SQL is generated based on the query that is designed.

Comments

    0 of 8192 characters used
    Post Comment

    • nicomp profile image
      Author

      nicomp really 8 years ago from Ohio, USA

      This masterpiece was hit 9 times today! That's 10% of the entire total over its lifetime!!

    • nicomp profile image
      Author

      nicomp really 8 years ago from Ohio, USA

      Why won't Google index this hub?

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: "https://hubpages.com/privacy-policy#gdpr"

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)