Query by Example
| Company type | Query language |
|---|---|
| Industry | Database management |
| Founded | January 1, 1970 |
| Founder | Moshé M. Zloof |
| Parent | IBM Research |
Query by Example (QBE) represents a database query language designed specifically for relational database systems.
History
Developed in the mid-1970s by Moshé M. Zloof at IBM Research, QBE emerged concurrently with SQL, drawing inspiration from Edgar Codd's foundational research on relational databases. It stands as the inaugural graphical query language, enabling users to formulate commands through visual tables populated with sample data and conditions. This innovative method streamlined data retrieval processes and was subsequently enhanced to accommodate operations such as inserts, deletes, updates, and the creation of temporary tables.
The architecture of QBE facilitates a parser that translates user inputs into database manipulation language commands like SQL, thereby minimizing the necessity for users to learn complex syntax. Consequently, it offers an efficient environment for both end-users and developers to construct queries by visually selecting tables and columns instead of manually entering their names.
In the field of information retrieval, QBE also describes a technique where example documents are submitted to extract similar records from a database, employing similarity searches based on document vectors (refer to Vector Space Model).
Acknowledged as a groundbreaking contribution to end-user development, QBE continues to influence academic research. Its functionality is integrated into relational database interfaces such as the "Visual Query by Example" feature in Microsoft Access and Microsoft SQL Server Enterprise Manager, along with some object-oriented databases like db4o.
The language’s foundation lies in the logical framework of tableau query, with enhancements analogous to how SQL extends relational algebra.
Example
The operation of QBE can be demonstrated through an example involving the Suppliers and Parts database.
| S | S# | SNAME | OWNER | SCITY |
|---|---|---|---|---|
| P.SX | J. DOE | ROME |
As a general technique
Inspired by Zloof's methodology, QBE permits users to specify search criteria simply by entering desired values, enabling query formulation without requiring proficiency in languages such as SQL. The system automatically generates corresponding queries. For example, consider a Contacts table with fields: Name, Address, City, State, Zipcode:
Contacts Query Form - Example A: .....Name: Bob ..Address: .....City: ....State: TX ..Zipcode:
Generated SQL: <syntaxhighlight lang="sql"> SELECT * FROM Contacts WHERE Name='Bob' AND State='TX'; </syntaxhighlight> Fields left empty do not contribute conditions.
Contacts Query Form - Example B: .....Name: ..Address: .....City: Sampleton ....State: ..Zipcode: 12345
Generated SQL: <syntaxhighlight lang="sql"> SELECT * FROM Contacts WHERE City='Sampleton' AND Zipcode='12345'; </syntaxhighlight> More sophisticated versions of QBE support comparison operators such as "Contains", "Not Contains", "Starts With", "Greater Than", among others.
Text matching can incorporate wildcards; for instance, an asterisk (*) serves as a placeholder matching variations like "Rob", "Robert", or "Robertson".
Contacts Query Form - Example C: .....Name: Rob* ..Address: .....City: ....State: ..Zipcode:
Generated SQL: <syntaxhighlight lang="sql"> SELECT * FROM Contacts WHERE Name LIKE 'Rob%' </syntaxhighlight>
Within SQL syntax, the percent sign (%) functions as the wildcard character; QBE converts user-friendly asterisks into percent signs accordingly.
CAUTION: To prevent unauthorized access via SQL injection, QBE implementations must include robust safeguards.
See also
- CRUD
- Microsoft Query by Example
- GraphQL – a QBE approach tailored for JSON interfaces.
- QBIC
External links
- Java Query by Example with Hibernate – JBoss
- Exploring OptiqueVQS: an ontology-driven, multi-paradigm visual query tool for users – Universal Access in the Information Society, 2015