Chapter 11: Queries in Base
1. Introduction to Queries
- Definition: A query is essentially a question asked to a database to search, filter, and retrieve specific records from one or more tables based on defined specifications.
- Purpose & Need:
- Displays desired fields and filters records according to criteria.
- Avoids manually scanning through large tables as record counts increase.
- Can retrieve and combine data from single or multiple related tables.
- Displays the output in a structured tabular form (field names in columns, records in rows).
- Key Feature in LibreOffice Base: Queries are saved as database objects so they can be run multiple times whenever needed.
2. Ways to Create a Query in LibreOffice Base
LibreOffice Base provides three ways to create a query:
- Using a Wizard
- In Design View
- In SQL View
3. Creating a Query Using a Wizard
The Query Wizard guides you step-by-step through setting up a query.
Steps in Query Wizard:
- Field Selection: Select the target table from the Tables list box, then select fields from Available Fields and move them to Fields in the Query using the right arrow (
>) button.>moves the selected field.>>moves all fields at once.</<<moves fields back to Available Fields.- Up (
▲) and Down (▼) buttons reorder fields in the query.
- Sorting Order: Set ascending or descending sorting for fields.
- Search Conditions (Criteria): Define criteria to filter records.
- At most 3 search conditions can be specified in the wizard.
- Options include Match all of the following (AND logic) or Match any of the following (OR logic).
- Summary & Calculation Steps (Steps 4–6): Skipped automatically if there are no numerical fields involved.
- Aliases (Step 7): Assign user-friendly column header names to replace raw field names in the output.
- Overview (Step 8): Displays a summary of all settings, the query name (default:
Query_Events), and allows choosing between Display Query or Modify Query upon finishing.
4. Creating a Query in Design View
Design View offers a flexible, detailed environment for creating simple or complex queries across single or multiple tables.
Structural Layout of Query Design Window:
The Query Design window is divided into two main panes:
- Tables Pane (Top Pane): Shows the selected table(s) and their relationships.
- Design Grid (Bottom Pane): Contains rows used to define the output fields and query behaviors.
Key Rows in the Design Grid:
| Grid Row | Function / Description |
| Field | Selected field name from the table. |
| Alias | Custom column header displayed in the query output. |
| Table | Name of the source table for the field. |
| Sort | Sort order (Ascending or Descending) for that field. |
| Visible | Checkbox (checked by default); uncheck to hide field data from the output. |
| Function | Mathematical/aggregate functions applied to the field. |
| Criterion | Condition(s) to filter rows (supports relational operators: <, >, <=, >=, =, !=). |
5. Editing and Running a Query
- Running a Query:
- Click the Run Query button on the toolbar, or press the shortcut key
F5.
- Click the Run Query button on the toolbar, or press the shortcut key
- Saving a Query:
- Click the Save icon; default name is
Query1(can be renamed).
- Click the Save icon; default name is
- Editing an Existing Query:
- Go to the Database window and select the Queries object tab.
- Right-click the query name in the Objects area and select Edit.
- Modify fields, sorting, aliases, or criteria in the Query Design window.
6. Working with Numerical Data and Aggregate Functions
Base provides mathematical functions in the Function row of the Design Grid to perform calculations on numerical fields.
- Available Aggregate Functions:
Sum,Average,Minimum,Maximum,Count, etc. - Grouping Data (
GroupOption):- Select
Groupin the Function row under a textual/categorical field to group identical values together. - Select an aggregate function (e.g.,
Average,Sum) under a numerical field to calculate values for each group.
- Select
- Criteria on Groups: You can also apply text or numeric criteria on grouped fields (e.g., setting
Criterionto"Athletics"under Category Name).
7. Textbook Solutions & Exercise Answers
A. Multiple Choice Questions
- Which of the following is refer to asking questions from the database?
- Answer: (c) Query
- Which of the following are the ways to design a query?
- Answer: (d) All of the above (Wizard, Design View, SQL)
- Which is a flexible way to create a query?
- Answer: (b) Design View
- Into how many parts is the query design window divided?
- Answer: (b) Two (Tables Pane & Design Grid)
- Which of the following is NOT true about queries?
- Answer: (d) A query once created cannot be edited
- Which of the following is the shortcut key to run the query?
- Answer: (c) F5
- Which of the following functions can be performed on numerical data while designing a query?
- Answer: (d) All of the above (Sum, Minimum, Maximum)
- In a Query Design wizard, which of the following buttons is clicked to move a field from ‘Available fields’ list box to ‘Fields in the query’ list box?
- Answer: (a) >
- Which of the following relational operators can be applied to set the criterion while designing a query in LibreOffice Base?
- Answer: (d) All of the above ( >, =, !=)
- Which of the following dialog box is present when the Query Design window is opened for the first time to design a query?
- Answer: (c) Add Table or Query
- Which of the following step is not performed if there is no numerical data to be worked upon in a query?
- Answer: (c) Summarizing
B. State Whether True or False
- You can run a query only once. — False
- A query cannot be created from multiple tables. — False
- The shortcut key to run a query is F5. — True
- LibreOffice Base provides us with two ways to create a query. — False (There are three ways)
- A query with numerical data cannot be saved. — False
- By default the query result is not sorted. — True
- A query can be used to display the average value of a numerical field. — True
- While designing a query, the criterion can be set on only one field. — False
- Alias is an alternative name for a field in a query. — True
- In query Design window, the visible check box is selected by default. — True
- A query once created using a wizard can only be edited in the Design view. — True
C. Fill in the Blanks
- A query is a sort of question asked from a database.
- The result of the query is displayed in tabular form with field names in columns.
- A query can be created in three ways.
- The Query Design window is divided into two sections.
- The shortcut key to run the query is F5.
- The conditions to filter the records are set in the Criterion row.
- When a table is selected in a Query wizard, the corresponding fields are displayed in the Available Fields list box.
- The result of the query can be displayed in ascending or descending order of any particular field of the table.
- At the most three search conditions can be given in the query wizard.
- The last step of the Query wizard displays the entire overview of the query.
- The Design view is a more flexible method to create a query.
- To edit any query, right click on the query icon of the query that has to be edited.
- In the Alias row of the Query Design grid, we can type the column heading that will be displayed instead of field name when we run the query.
D. Descriptive Answer Questions
1. Define a query? What is the need of creating a query in a database?
- Answer: A query is a question or specification given to a database to search, filter, and retrieve specific records from one or more tables.
- Need: As database size grows, manually finding specific records becomes difficult. Queries allow users to retrieve targeted information instantly based on defined criteria and present it in a formatted tabular layout.
2. Rearrange the steps given below so as to create a query using a wizard:
- Given Steps: 1. Give Alias, 2. Select the fields, 3. Set the criterion, 4. Set the sorting order, 5. Give table name
- Correct Sequence:
- Give table name (Select Table)
- Select the fields
- Set the sorting order
- Set the criterion
- Give Alias
3. What all information is seen in the overview (last step) of the Query wizard?
- Answer: The Overview screen shows:
- The name of the query (with an option to rename it).
- Action choices after wizard completion (Display Query or Modify Query).
- A summary of selected fields, sorting rules, search criteria, and assigned aliases.
4. What is the use of Alias row in the Design grid of the Query Design window?
- Answer: The Alias row allows users to specify custom, readable column headers for the output instead of displaying raw field names from the database tables.
5. Name any four mathematical functions that can be applied to numerical data in a query.
- Answer:
Sum,Average,Minimum, andMaximum.
6. Name the three ways of creating a query in LibreOffice Base?
- Answer:
- Using a Wizard
- In Design View
- In SQL View
