Sorting and Queries

advertisement
Sorting and
Queries
1 of 12
© Boardworks Ltd 2010
This lesson will cover:
Basic sorting in a database.
Creating a basic query.
Creating and using advanced queries.
Icons key:
For more detailed instructions, see the Getting Started presentation
Flash activity. These activities are not editable.
Teacher’s notes included in the Notes Page
Student task accompanies this slide
2 of 12
Web addresses
Functional Skills check
Printable activity
© Boardworks Ltd 2010
Sorting and queries
Learning to sort and use queries in databases is incredibly
useful as it can allow you to pinpoint the exact data you require.
Can you think of examples of where this is used?
3 of 12
© Boardworks Ltd 2010
Basic sorting
Databases are extremely useful as they allow you to create
tables of related data which can then be searched and
sorted as needed.
Right-clicking on one of the field headings and then
choosing Sort Ascending will put the
data in ascending alpha-numerical order.
Alternatively, you can highlight a field and
click on either of these icons on the toolbar.
4 of 12
© Boardworks Ltd 2010
Queries
Databases are used for searching and sorting vast quantities
of data and producing results that match criteria. To search or
sort a database in this way requires the creation of a query.
To create a query:
Select Queries from the Objects menu. You
can then choose to use the Wizard or Create
query in Design view.
When you are creating queries in design view, you will be able
to select sorting options for multiple fields.
You can also save queries and produce a report
with the data you have obtained.
5 of 12
© Boardworks Ltd 2010
Creating queries
This query has been set up to sort by age, but within each age
group the results are to be sorted alphabetically by surname.
The top line of the query specifies the fields to be displayed.
The second line
specifies which
table will provide
the data.
6 of 12
The third line
selects if the data
is to be sorted in
ascending or
descending order.
Remember to tick
the show boxes or
your data will not
be displayed.
© Boardworks Ltd 2010
Advanced queries
Database queries really come into their own when you want
to put together advanced searches.
Imagine you had a database of valued customers. What if
you wanted to find all the customers under thirty, living in
London who spent over a £1,000 in the previous year.
This would take you a long time to find on paper reports, but
with a database query it can be done very simply.
Table name Customers
Living
under 30 in London
7 of 12
Spent over
£1,000
© Boardworks Ltd 2010
Advanced queries
Entering data into the criteria box allows you to be very
selective about what data is returned.
To help with this you can use logical and relational operators.
Example
Logical operators
A forename search for “Pete” OR
(AND, OR and NOT)
“Peter” will return results for anyone
help to create logic
statements for queries. called Pete or Peter.
Relational operators
(=,<,>,=,<=,>=) help
to construct
range statements.
8 of 12
Example
An age search for >=14 AND <= 18
will return all the records with ages
between 14 and 18.
© Boardworks Ltd 2010
Logical and relational operators
9 of 12
© Boardworks Ltd 2010
Match them
10 of 12
© Boardworks Ltd 2010
Using a query
11 of 12
© Boardworks Ltd 2010
Revision
12 of 12
© Boardworks Ltd 2010
Download