Working with databases/Database queries/Simple queries

From WikiEducator
Jump to: navigation, search
OtagoPoly Logo S.png






OP icon activity.gif

Activity

Please note: the following tutorial will open in a new window/tab. When you have finished the tutorial, simply close the window/tab and you'll return to this page.

Before you go on, please work through the following tutorial:

  • Using Queries to Make Data Meaningful - Part 1





Creating a simple query

A query allows us to analyse data contained in our table. With a query we can:

  • Retrieve only the particular records that we want
  • Filter out (or hide) data that does NOT meet a criteria (value)

A query is based on the fields in a table and can contain all of the fields in the table or some of the fields. When designing a query, you would look at the brief to decide what you need to show.

A query can be saved and re-used.

For example, from this table we could create a query that:

  • Produces a list of students in alphabetical order
  • Sorts students by address
  • Shows only students who have scored higher than 75% in their subjects
  • Shows students who are missing exam marks.

Access-query1.png



OP icon activity.gif

Activity

Using our bookshop database, we’re going to step you through the process of creating a simple query that will show us all books that are hardcovers.

  1. Open your bookshop database
    • In Office 2007 choose Create Tab ⇒ Other Group ⇒ Query Wizard
    • In Office 2010 choose Create Tab ⇒ Queries Group ⇒ Query Wizard
  2. From the dialogue box, choose Simple Query Wizard
    The Tables/Queries dropdown menu shows us tables we can use to make our query with. In this case we have only one – Books.

    Access-query3.png
    The Available Fields menu shows us the fields in the selected table that we can use. We use the > button to promote fields into the Selected Fields box. These selected fields are what will actually be used to make our query.
  3. Use the > button to promote the following fields from your table into the selected fields menu:
    • Title
    • Year published
    • Author
    • Paperback book
  4. Click Next. From the next box that pops up, choose Detail then click Next.
  5. Give your query the name QRY_Paperbacks. Click on Finish.

You should end up with a screen that looks like the following picture:

Access-criteria1.png

Don’t forget to save your database.