ArticleslgStudy

computer science

Query by Example

Query by Example is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Query by Example rather than just read about it. In short: Query by Example (QBE) is a database query language for relational databases. History Query by Example was devised by Moshé M.

Query by Example — main illustration
Query by Example — illustration

Key takeaways

  • Query by Example belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Query by Example to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Query by Example from memory before moving on to harder problems.

Reference excerpt

Query by Example (QBE) is a database query language for relational databases.

History Query by Example was devised by Moshé M. Zloof at IBM Research during the mid-1970s, in parallel to the development of SQL, and influenced by the work on relational databases of Edgar Codd. It is the first graphical query language, using visual tables where the user would enter commands, example elements and conditions. Many graphical front-ends for databases use the ideas from QBE today. Originally limited only for the purpose of retrieving data, QBE was later extended to allow other operations, such as inserts, deletes and updates, as well as creation of temporary tables. The motivation behind QBE is that a parser can convert the user's actions into statements expressed in a database manipulation language, such as SQL. Behind the scenes, it is this statement that is actually executed. A suitably comprehensive front-end can minimize the burden on the user to remember the finer details of SQL, and it is easier and more productive for end-users (and even programmers) to select tables and columns by selecting them rather than typing in their names. In the context of information retrieval, QBE has a somewhat different meaning. The user can submit a document, or several documents, and ask for "similar" documents to be retrieved from a document database [see search by multiple examples]. Similarity search is based comparing document vectors (see Vector Space Model). QBE represents seminal work in end-user development, frequently cited in research papers as an early example of this topic. Currently, QBE is supported in several relational database front ends, notably Microsoft Access, which implements "Visual Query by Example", as well as Microsoft SQL Server Enterprise Manager. It is also implemented in several object-oriented databases (e.g. in db4o). QBE is based on the logical formalism called tableau query, although QBE adds some extensions to that, much like SQL is based on the relational algebra.

Example An example using the Suppliers and Parts database is given here to illustrate how QBE works.

As a general technique The term also refers to a general technique influenced by Zloof's work whereby only items with search values are used to "filter" the results. It provides a way for a software user to perform queries without having to know a query language (such as SQL). The software can automatically generate the queries for the user (usually behind the scenes). Here are two examples based on a Contacts table with the following text (character) columns: Name, Address, City, State, and Zipcode:

Contacts Query Form - Example A: .....Name: Bob ..Address: .....City: ....State: TX ..Zipcode:

Resulting SQL:

Note how blank items do not generate SQL terms. Since "Address" is blank, there is no clause generated for it.

Contacts Query Form - Example B: .....Name: ..Address: .....City: Sampleton ....State: ..Zipcode: 12345

Resulting SQL:

More advanced versions of QBE have other comparison operator options, often via a pull-down menu, such as "Contains", "Not Contains", "Starts With", "Greater-Than", and so forth. Another approach to text comparisons is to allow one or more wildcard character characters. For example, if an asterisk is designated as a wildcard character in a particular system, then searching for last names using "Rob*" would return (match) last names such as "Rob", "Robert", "Robertson", "Roberto", etc.

Contacts Query Form - Example C: .....Name: Rob* ..Address: .....City: ....State: ..Zipcode:

Resulting SQL:

In standard SQL, the percent sign functions like a wildcard in a LIKE clause. In this case, the query-by-examplme form processing software would translate the asterisk to a percent sign. (An asterisk is a more common wildcard convention outside of SQL, so here the form is attempting to be more user friendly.) WARNING: Query-by-example software should be careful to avoid SQL injection. Otherwise, devious users may penetrate further into the database than intended by builders of the query forms.

See also CRUD Microsoft Query by Example GraphQL a QBE for JSON front-ends. QBIC

References

Sources

External links "Query by Example in Java using Hibernate". JBoss. Soylu, Ahmet; Giese, Martin; Jimenez-Ruiz, Ernesto; Vega-Gorgojo, Guillermo; Horrocks, Ian (2015). "Experiencing OptiqueVQS: a multi-paradigm and ontology-based visual query system for end users" (PDF). Universal Access in the Information Society. 15: 129–152. doi:10.1007/s10209-015-0404-5. hdl:11250/2388519. S2CID 254169347. Archived from the original (PDF) on 2022-12-05. Retrieved 2021-11-12. Visual Query System (VQS)

Illustrations

Query by Example: Example of QBE query with joins, designed in Borland's Paradox database
Example of QBE query with joins, designed in Borland's Paradox database

Worked examples

Example 1 — a first encounter with Query by Example

Start with the simplest possible case. Write down what Query by Example claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Query by Example before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Query by Example ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Query by Example

In research
Query by Example appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Query by Example in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Query by Example is common in secondary-school and first-year university syllabi. It links to neighbouring topics 1970s software, Human–computer interaction, IBM software, so understanding it makes those chapters shorter.
In everyday life
Look for Query by Example outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Query by Example in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Query by Example means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Query by Example out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Query by Example in simple terms?

Query by Example (QBE) is a database query language for relational databases. History Query by Example was devised by Moshé M.

Why does Query by Example matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Query by Example?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Query by Example.

Tags

  • 1970s software
  • Human–computer interaction
  • IBM software
  • Query languages
  • Relational model

Keep exploring