MS Access Query Data
MS Access Query Data
MS Access Query Data
Data
QUERY
A query is a request for data results, and
for action on data.
You can use a query to answer a simple
question, to perform calculations, to
combine data from different tables, or
even to add, change, or delete table data.
•As tables grow in size they can have hundreds of
thousands of records, which makes it impossible for
the user to pick out specific records from that table.
•With a query you can apply a filter to the table's
data, so that you only get the information that you
want.
•Queries that you use to retrieve data from a table
or to make calculations are called select queries.
•Queries that add, change, or delete data are called
action queries.
•You can also use a query to supply data for a form or
report.
•In a well-designed database, the data that you want to
present by using a form or report is often located in
several different tables.
•The tricky part of queries is that you must understand
how to construct one before you can actually use them.
Create Select Query
If you want to review data from only
certain fields in a table, or review data
from multiple tables simultaneously
or maybe just see the databased on
certain criteria, you can use the Select
query.
Let us now look into a simple example
in which we will create a simple query
which will retrieve information from
tblEmployees table. Open the
database and click on the Create tab.
Click Query Design.
In the Tables tab, on the Show Table
dialog, double-click the tblEmployees
table and then Close the dialog box.
In the tblEmployees table, double-
click all those fields which you want to
see as result of the query. Add these
fields to the query design grid as
shown in the following screenshot.
Now click Run on
the Design tab, then
click Run.
MS Access - Query Criteria
Query criteria helps you to retrieve specific items from an Access database. If
an item matches with all the criteria you enter, it appears in the query
results. When you want to limit the results of a query based on the values in
a field, you use query criteria.
•A query criterion is an expression that Access compares to query field values
to determine whether to include the record that contains each value.
•Some criteria are simple, and use basic operators and constants. Others are
complex, and use functions, special operators, and include field references.
•To add some criteria to a query, you must open the query in the Design View.
•You then identify the fields for which you want to specify criteria.
Example
Let’s look at a simple example in which we will use
criteria in a query. First open your Access database and
then go to the Create tab and click on Query Design.
In the Tables tab on Show Table dialog, double-click on
the tblEmployees table and then close the dialog box.
Let us now add some field to the query grid such as
EmployeeID, FirstName, LastName, JobTitle and Email
as shown in the following screenshot.
Let us now run your query and you will see only these
fields as query result.
An action query cannot be undone. You should consider making a backup of any
tables that you will update by using an update query.
Create an Append Query
You can use an Append Query to
retrieve data from one or more
tables and add that data to
another table. Let us create a new
table in which we will add data
from the tblEmployees table.
This will be temporary table for
demo purpose.
Let us call it TempEmployees and
this contains the fields as shown in
the following screenshot.
In the Tables tab, on the Show
Table dialog box, double-click
on the tblEmployees table
and then close the dialog box.
Double-click on the field you
want to be displayed.
Let us run your query to
display the data first.
Now let us go back to Query design
and select the Append button.
In the Query Type, select the Append
option button. This will display the
following dialog box.
Select the table name from
the drop-down list and click
Ok.
In the Query grid, you can see
that in the Append To row all
the field are selected by
default except Address1.
This because that Address1
field is not available in
the TempEmployee table.
So, we need to select the field
from the drop-down list.
Let us look into the Address
field.