Designing Queries with Multiple Criteria

Master the art of asking precise questions to extract exactly what you need from your database!

1

What is a Query? (The Question)

The Concept: A query is a specific "question" you ask the database. It's like having a conversation with your data!

The "Subset" Idea: Queries don't create new data; they simply display a specific view of existing data. Think of it as putting filters on a camera lens.

The Search Bar vs. The Query

Type "Blue Shoes" to see how a query scans the database and returns only matching results!

Product Database (1,000 items)
2

The Logic of "AND" vs. "OR" (Objective 12)

The "AND" Criteria (The Specialist)

Both conditions must be true. Example: Color = "Red" AND Size = "Large"

Result: Fewer, more specific records. Think of it as narrowing down your search.

The "OR" Criteria (The Generalist)

Either condition can be true. Example: City = "Kingston" OR City = "Montego Bay"

Result: More records, broader search. Think of it as expanding your options.

The Logic Gate

Drag criteria into the circles and toggle between AND/OR to see how results change!

Grade = '11'
Subject = 'Math'
Score > 80
Criteria A
Criteria B
AND Results: 0

AND: Both conditions must be true (overlap area)

OR: Either condition can be true (entire circles)

3

Using Relational Operators

The Symbols

  • > (Greater than)
  • < (Less than)
  • >= (Greater than or equal to)
  • <= (Less than or equal to)
  • <> (Not equal to)

Complex Combinations

Example: Price > 50 AND Price < 100 finds items in a specific price range.

The Price Slider

Drag the handles to set a price range. Watch the query criteria update in real-time!

$0
$200
Query Design Grid
Price > 0 AND Price < 200

This query will find all products in the selected price range.

4

Querying Text: Wildcards and Exact Matches

Exact Match

Searching for exact text: "Grade 11" will only find records with exactly "Grade 11".

The Wildcard (* or %)

  • Sm* finds Smith, Small, and Smart
  • *son finds Johnson, Thompson, and Mason
  • A*e finds Anne, Alice, and Adele
  • *car* finds racecar, cardboard, and car
Wildcard Searcher

Type a search pattern with asterisks (*) to see which student names match your wildcard!

Use * as a wildcard for any characters. Example: "Jo*" matches "John", "Joanna", "Jones"

Matches found: 0 students

5

The Design Grid (Query View)

Anatomy of the Grid

  • Field: Which column are we looking at?
  • Table: Which table does it come from?
  • Sort: Ascending (A-Z) or Descending (Z-A)?
  • Show: Do we want this column to appear in the final answer?
  • Criteria: The actual rules we are setting
Query Builder

Build a query to solve: "Find all students who scored over 80 in Math"

Available Fields

StudentID
FirstName
LastName
Subject
Score
Grade

Query Design Grid

Drag fields here to add to query
Field Table Sort Show Criteria
6

CSEC SBA Focus: Multi-Table Queries

The Joins

Queries can pull data from two related tables. Example: Student Name from Students table and Grade from Grades table.

Common Error

Forgetting to link tables results in a Cartesian Product - every student matched with every grade (incorrect!).

Multi-Table Query Visualizer

Watch how data from two tables combines correctly when properly linked!

Students

StudentID: 1001

Name: Maria

Grade: 11

Grades

GradeID: 501

StudentID: 1001

Subject: Math

Score: 92

Query Result (Correct Join)

Maria (StudentID: 1001) scored 92 in Math

The tables are linked by StudentID, so each student is correctly matched with their grades.

Cartesian Product (Wrong - No Link)

If tables aren't linked, you'd get:

• Maria matched with ALL grades

• David matched with ALL grades

• Every student × every grade = Incorrect results!

7

Knowledge Check: The Query Master

Logic Challenge

"You need to find all employees who work in the 'Sales' department AND earn more than $3000."

Which criteria line is correct?

"Sales" OR >3000
"Sales" AND >3000
Sales > 3000
"Sales" = >3000

The "Fix the Formula" Quiz

A query is returning 0 results. Look at the criteria below and explain why it's logically impossible:

Score > 100 AND Score < 50
Scroll to Top