CSE1IS Information Systems
Week 7

La Trobe University, Bendigo campus Department of Computer Science an
d Computer Engineering
 

MS-Access queries


1.  Introduction:

The Query design screen provides a mechanism for selecting specific data from data table(s), by:

2.  MS-Access Query Screen:

Tables Panel :       contains top section which shows the tables to be used in the query
Selection and Criteria Panel:       contains fields and criteria used in the query


Selecting Fields:

3.  Selecting Records using a Criteria:

Enter criteria into criteria lines at the bottom section of the query design screen.

3.1 Criteria operators:

Different field types specify criteria slightly differently:

3.2 Like operator can contain Wild characters:

3.3 Character field:

3.4 Numeric fields:

3.5 Date fields:

3.6 Logical Fields:

eg. 1:

Field: POSITION PAY_RATE  
Sort:      
Show: X X  
Criteria: ìForwardî    
Or:      
This shows a specific criteria, but you can also specify a range of values:
      i.e.             <= ìMî
                  Between ìDî AND ìHî
                  Like ìFor*dî
 
eg. 2:
Field: POSITION PAY_RATE UNION
Sort:      
Show: X X  
Criteria: Like ìB*î    
Or:   >8.50 Yes
 
eg. 3:
Field: NAME PAY_RATE DOB
Sort:   Ascending  
Show: X X  
Criteria: Like ìB*î    
Or:   <= 7 >#01/01/70#
 

eg. 4:

Field: NAME UNION DOB
Sort:      
Show: X X  
Criteria: Like ì*arry*î No  
Or:     <#12/12/75#

4. Multiple Criteria:

4.1  Condition1  AND  Condition2

Field: DEPARTMENT PAY_RATE  
Sort:      
Show: X X  
Criteria: ìAccountingî > 7.00  
Or:      

eg. 2.

Pay_Rate between 7.00  AND  9.50

Field: DEPARTMENT PAY_RATE  
Sort:      
Show: X    
Criteria:   Between 7.00 AND 9.50  
Or:      

          OR

Field: DEPARTMENT PAY_RATE  
Sort:      
Show: X    
Criteria:   >7.00 AND < 9.50  
Or:      


4.2  Condition1  OR  Condition2

Enter conditions on different lines in table skeleton:

eg. 1: Department is either "Accounting" OR  "Computing"

Field: DEPARTMENT PAY_RATE  
Sort:      
Show: X X  
Criteria: ìAccountingî    
Or: ìComputingî    

eg. 2: Pay_rate > 9.00 OR Department = "Computing"

Field: DEPARTMENT PAY_RATE  
Sort:      
Show: X X  
Criteria:   > 9.00  
Or: ìComputingî    

5.  Ordering of records:

MS-ACCESS sorts ascending/descending on most of the data types 
ie. text, numeric, date and yes/no fields.

6. Concatenating Fields:

Field: personID    fullname: lastname & ", " & firstname other cols
Sort:   Ascending  
Show:   X   X  
Criteria:           
Or:      

7.  Linking Tables:

Performed within a query. Usually linked on a common field.
eg. Table1: Sales table (FLYSALE)

Customer         Qty         Itemcode    
Mark
Brenda
Jane
Carol
    :
2
6
1
4
:
C1
D2
P1
C1
:

Table2: Inventory table  (FLYINVEN)

  Itemcode    Description     Price
C1
C2
D2
P1
Pentium
486
Diskettes
Printer
   2,200.00
1,500.00
8.50
750.00

Results of linked query:

Customer      Qty     Itemcode   Description    Price
Mark
Brenda
Jane
Carol
    :
2
6
1
4
:
C1
D2
P1
C1
  :
Pentium
Disks
Printer
Pentium
  :
  2,200.00
8.50
750.00
2,200.00
  :



Query setup: The query automatically selects the correct record from FLYINVEN for each sale.

Valid XHTML 1.0 Strict

copyright © 2006 Brian Retallick. This page last updated on Thursday 28 August 2008 by Noel McEwan, La Trobe University, Bendigo