QBE (Query By Example)

Comprehensive study notes, diagrams, and exam preparation for QBE (Query By Example).

QBE (Query By Example)

Definition

Query By Example (QBE) is a database query technique in which the user specifies the desired data by entering example values and conditions into a predefined query template or table-like form, and the DBMS interprets these entries to generate and execute the corresponding query.

In simple words, QBE is a form-based query language where users do not need to write SQL directly; they only need to provide examples of the required data.


Main Content

1. QBE as a Visual Query Language

  • QBE uses tables, grids, or forms to represent database relations, making it easier to understand than text-based query languages.
  • The user fills in the example values directly into cells under column names, and these values act as query conditions.

A QBE screen usually resembles a table with rows and columns. For example, if a table named STUDENT has columns such as RollNo, Name, Class, and Marks, a user can place a value like Amit under Name to find all records related to Amit.

Example idea:

RollNo Name Class Marks
Amit

This means: retrieve all records where the name is Amit.

QBE is called “visual” because the structure itself communicates the query logic. This reduces the need to memorize command syntax and helps users quickly formulate queries.

2. QBE Conditions and Operators

  • QBE supports selection conditions such as equality, inequality, ranges, and pattern matching.
  • Special symbols or keywords are used to express logical conditions like AND, OR, greater than, less than, and not equal.

For example:

  • > 75 may mean marks greater than 75
  • < 20 may mean age less than 20
  • != Mumbai may mean city is not Mumbai
  • Pattern matching may use symbols like * or % depending on the system

If a user wants students with marks greater than 80, the query form may include:

Name Marks
>80

This means fetch all records where Marks > 80.

QBE can also express combined conditions. For example, if the user wants students in class 12 with marks above 90, both conditions are entered in the corresponding cells. The DBMS interprets this as an AND condition unless otherwise specified.

3. QBE for Database Operations

  • QBE is not limited to retrieving data; it can also support insert, update, delete, and join operations.
  • It provides a practical and uniform way to manipulate data through examples rather than explicit programming.

Retrieval (SELECT):
If a user wants to find employee details of those working in the HR department, the QBE form may contain HR under the Department field.

Insertion (INSERT):
New values can be entered into the example grid to add a new record.

Modification (UPDATE):
Existing values can be matched using conditions and then replaced with new values.

Deletion (DELETE):
Records satisfying a condition can be identified and removed.

Join operations:
QBE can combine tables by matching common fields. This is useful when information is distributed across multiple related tables.

For example, if STUDENT and RESULT tables are connected through RollNo, QBE can be used to fetch student names along with marks by linking the two tables visually.


Working / Process

1. Identify the required data

  • The user first decides what information is needed.
  • Example: “Find all students who scored more than 85 in Mathematics.”

2. Fill in the example grid

  • The user enters conditions in the relevant columns of the QBE table.
  • Example: Under Subject, write Mathematics; under Marks, write >85.

3. Execute and obtain results

  • The DBMS interprets the example values as query conditions.
  • It searches the database, applies selection/join/project logic, and displays the matching records.

A simple flow:

User requirement
      ↓
Enter examples in QBE form
      ↓
DBMS interprets conditions
      ↓
Query is executed
      ↓
Matching records are displayed

If multiple tables are involved, the user may also specify common attributes to create joins. The QBE engine then processes the relationships and returns combined results.


Advantages / Applications

Easy to learn and use

  • for beginners because it avoids complex query syntax.

Reduces syntax errors

  • since users enter conditions in a structured form rather than writing commands manually.

Useful in educational and practical environments

  • where users need quick access to database information without deep programming knowledge.

QBE is commonly applied in:

  • Database teaching and training
  • Form-based database interfaces
  • Business reporting tools
  • Data retrieval in user-friendly applications
  • Systems where non-technical users query data

It is especially helpful when users know what they want but not how to write the exact query language statement.


Summary

  • QBE is a visual method for querying databases using example values in a form.
  • It helps users retrieve and manipulate data without writing full SQL commands.
  • QBE is simple, intuitive, and especially useful for beginners and non-programmers.
  • Important terms to remember: Query By Example, visual query language, selection, projection, join, condition