Definition
Query by Example (QBE) is a visual method of querying databases where users fill in example values in a table template to specify what data they want.
Key Point
QBE Characteristics:
• Visual interface - no need to learn SQL syntax
• Fill in values in a grid/table format
• Criteria entered in same row = AND
• Criteria entered in different rows = OR
• Check boxes select which fields to display
• Visual interface - no need to learn SQL syntax
• Fill in values in a grid/table format
• Criteria entered in same row = AND
• Criteria entered in different rows = OR
• Check boxes select which fields to display
Worked Example
QBE Example
Query: Find all Year 12 students studying Computer Science
How to read this:
• Row criteria: Year = 12 AND Course = 'CompSci'
• Show ticked for StudentID and Name only
• Result shows StudentID and Name of matching records
For OR conditions, use multiple rows:
This finds Year 12 students OR students studying Maths
Query: Find all Year 12 students studying Computer Science
| Field | StudentID | Name | Year | Course |
|---|---|---|---|---|
| Show | ☑ | ☑ | ☐ | ☐ |
| Criteria | 12 | CompSci |
• Row criteria: Year = 12 AND Course = 'CompSci'
• Show ticked for StudentID and Name only
• Result shows StudentID and Name of matching records
For OR conditions, use multiple rows:
| Field | Year | Course |
|---|---|---|
| Criteria Row 1 | 12 | |
| Criteria Row 2 | Maths |
Exam Tip
Exam Comparison: SQL vs QBE
| Feature | SQL | QBE |
|---|---|---|
| User interface | Text commands | Visual grid |
| Learning curve | Steeper | Easier for beginners |
| Flexibility | Very flexible | Limited but intuitive |
| Precision | Exact syntax required | Visual selection |
| Use case | Programmers, power users | End users, simple queries |