Two Ways of Sorting Data: Getting Information Out of A Database
Two Ways of Sorting Data: Getting Information Out of A Database
Sorting
Sorts ascending or descending on any field
Queries
1
Query Window Query Windows (cont.)
Field: name of an attribute involved
in the query
Table: table where the field is found
Sort : the query will be sorted
according to this field
= Table(s) from which
Sort Key: Attributes on which the
to choose fields query will be sorted
Compound Sort Key
No Show
711-73-2486 Yep Lisa 42A Greer Fremont 95110 F 25 73000 2 Z
141-71-5901 Sorensen Scott 103 Pleasant San Mateo 94335 M 26 85000 1 X
293-21-7720 Vazquez Raul 4320 Mission Daily City 94017 M 21 75000 3 S3
566-02-5572 Drobnis Gloria 2 Glenellen Daily City 94012 F 27 76200 1 S3
2
SSN LName FName Address City Zip Sex Age Salary DepID ProjectID Another Simple Query
Using a Range Criterion
523-41-0727 Lee Tony 5. Blue Ct. Sausalito 94252 M 23 67000 1 X
DYNASET
3
Query : Or Condition Query: And between several
between two fields fields
Display employees who lives in Palo Alto or are males Display employees who are males and live in Sausalito
City = “Sausalito”
City = “Palo Alto”
AND
OR
Sex = “M”
Sex = “M”
4
Condition for fields Condition for fields
that contains any value that does not contain any value
Display SSN, Last Name and First Name of Display SSN, Last Name and First Name of
employees who are assigned to any project employees who are not assigned to any project
TRUE The field contains a value (any value) TRUE The field does not contains a value ( Null Value)
Is Not Null Is Null
FALSE The field does not contains a value ( Null Value) FALSE The field contains a value (any value)
Display the SSN, Last Name, First Name and the 523-41-0727 Lee Tony 5. Blue Ct. Sausalito 94252 M 23 67000 1 X
141-71-5901
Yep
Sorensen
Lisa
Scott
42A Greer
103 Pleasant
Fremont
San Mateo
95110
94335
F
M
25
26
73000
85000
2
1
Z
+
Access Joins the Tables by matching Dept.ID Dept.Name.
141-71-5901 Sorensen Scott 103 Pleasant San Mateo 94335 M 26 85000 1 X Accounting
293-21-7720 Vazquez Raul 4320 Mission Daily City 94017 M 21 75000 3 S3 Sales
222-02-222 Lee Bruce 23 Port Rd. Beverly Hills 94016 M 28 75000 3 S3 Sales
How does it work ? 111-01-111 Sorensen Marie 103 Pleasant San MAteo 94335 F 25 50000 1 Accounting
5
How does it work ? Calculated Fields
Apply Criteria : Sex = “F”
SSN
711-73-2486
LName
Yep
FName
Lisa
Address
42A Greer
City
Fremont
Zip
95110
Sex
F
Age
25
Salary
73000
DepID
2
ProjectID
Z
Dep. Name
Payroll
Used to compute values in a query:
566-02-5572
111-01-111
Drobnis
Sorensen
Gloria
Marie
2 Glenellen
103 Pleasant
Daily City
San MAteo
94012
94335
F
F
27
25
76200
50000
1
1
S3 Accounting
Accounting
Syntax: calculatedFieldName:expression
Any field name included in the expression
Remove fields: must be between brackets
LName FName Dep. Name
Yep
Drobnis
Lisa
Gloria
Payroll
Accounting
FirstInitial:Left([First Name],1)
Sorensen Marie Accounting
DYNASET
6
Display total number of employees
Some queries using statistics of the company
Display for each department, department Display the average salary of the employees
name and its number of employees that works for the Accounting Department
7
Display for each department, its name and Display the maximum number of
the average salary of its employees employees assigned to a project
1. Create a query to compute the number of
employees per project
Display the maximum number of Display for each project, its name and its
employees assigned to a project (cont.) number of employees assigned to it
2. Create a query that uses the previous created 1. Create a query to compute the number of employees
query to compute the maximum number of per project (We can use the previous one)
employees in a project
8
Display for each project, its name and its
number of employees assigned to it (cont.) Parameter Queries
2. Create a new query that include the table
project and the previous query A parameter query is a query that when executes
displays its own dialog box prompting the user
for information.
For example:
Access automatically
sets a relationship for
this query between Display SSN, First Name and Last name of all
the project table and
the appropriated field employees who lives in a city provided by the
in previous query user
Display SSN, First Name and Last name of all Display SSN, First Name and Last name of all
employees who lives in a city provided by the user employees whose salary is in a salary range
provided by the user