Friday, March 17, 2017

Create a select query

Create a select query

A select query helps you get just the data you need in a Datasheet view. The Product table in the top of the picture below has multiple columns, but with a select query, you can get an uncluttered view that focuses on just the columns you need.

The side by side view of the table and the query results.

You can also add criteria to filter the number of rows returned. For example, find only those products that cost more than $10.00.

Tip:  A select query also works well when you need to pull data from several related tables, group data, or to calculate totals.

In this article, we'll see how to create a simple select query in both desktop databases and Access apps.

Create a select query in a desktop database

For example, in a desktop database with a Products table, to see only the product names and the price for each product, you can create a select using the Query Wizard: On the Create tab, click Query Wizard and let the wizard walk you through the process of creating and running the query.

However, if you want to add criteria to your query, use the query designer:

  1. Click Create > Query Design.

  2. In the Show Table box, double-click the Products table > Close.

  3. To add the fields to the design grid, double-click the Product Name and List Price fields.

  4. In the criteria row, under List Price add a criteria. For example, >=10 to show a list of products more than or equal to $10.00.

Query designer with criteria

  1. To see the query results, on the Design tab, click Run.

Select query results with criteria added

Create a select query in an Access app

Creating the same select query in a web-based Access app is similar to the procedure above, with just a little extra bit of work to make the query results available in the browser:

  1. Click Home > Advanced > Query.

  2. In the Show Table box, double-click the Productstable > Close.

    Query designer view highlighting the query tab

  3. To add the fields to the design grid, in the Products box, double-click Product Name and List Price.

  4. Right-click the query tab > Save and give your query a name.

  5. To see the query results, right-click the query tab > Datasheet View.

To make the query results available on the browser view, you need to add a view of the query to the source table (Product table):

  1. Select the Products table.

Adding a Datasheet view of the query to the source table.

  1. Click the plus icon, enter a view name, and select Datasheet from the View Type drop-down.

  2. In the Record Source drop-down, select the query that you want displayed, and click Add New View.

    Tip:  If you used multiple tables in a query, you can add the view to any or all tables.

No comments:

Post a Comment