Internet
Fact-checked

At EasyTechJunkie, we're committed to delivering accurate, trustworthy information. Our expert-authored content is rigorously fact-checked and sourced from credible authorities. Discover how we uphold the highest standards in providing you with reliable knowledge.

Learn more...

What is Query by Example?

Derek Schauland
Derek Schauland

Query by example (QBE) is a query language for relational databases similar to Structured Query Language (SQL). The "by example" portion of this data gathering language allows the person or application looking to retrieve data from the relational database to complete the information that they know about the data they are looking for. The Query by example method might include a form that the user would complete to generate a SQL query that the database understands.

Suppose for example that there existed a database full of employees in an organization and this information was made available to the employees in case they needed to communicate with other employees. The database storing the information understands commands like select fname from employees where lname = 'smith', however many people do not understand this type of syntax. Query by example can help with this. The following statement:

select fname, lname, extension from employees where lname ='smith'

Woman doing a handstand with a computer
Woman doing a handstand with a computer

tells the database to look through the employees table of information and display all of the first names (fname), last names, (lname), and phone extensions (extension) where the last name field contains the value smith. Using a QBE style query, the user looking for this information could provide the information that they know, last name = 'smith', and see the information related to that last name. This allows the employee to give an example of what they are looking for and see the results returned.

The query sent to the database in the above example looks just like the SQL statement shown above, even though the person performing the lookup told the database only that the last name was Smith and then which items he or she needed to know, the first name, last name, extension. Since most query by example use involves a form or application for data entry, the table employees could be hard coded into the system so the users do not need to worry about that.

Another similar example is the recipient lookup used by Microsoft Outlook Web Access®. When someone clicks the To field header, another form opens up allowing that person to complete the items they know about and click the find button, all records matching the specified example will be returned and the employee can click the correct information to use it in an email message.

Discuss this Article

Post your comments
Login:
Forgot password?
Register:
    • Woman doing a handstand with a computer
      Woman doing a handstand with a computer