Mada za sehemu hiiWorking with presentation applicationsMada 5
A query is a question you ask a database to find specific information from your stored data. Instead of looking through all records one by one, a query searches the database and displays only the records that match your needs.
A query is a tool that helps you retrieve, filter, and organize data from one or more tables in a database. It answers questions like "Which students scored above 80 in Mathematics?" or "Which products cost less than TZS 5,000?" By creating a query, you can extract useful information quickly without changing the original data.
Queries are important because they help you make decisions based on accurate, filtered data rather than looking at all records at once.
Select Query
This is the most common type. It retrieves data from one or more tables based on conditions you set and displays the results in a datasheet view.
Action Query
This type not only finds data but also makes changes to it. Action queries include:
- Update Query – Changes values in existing records
- Append Query – Adds new records to a table
- Delete Query – Removes records from a table
- Make-Table Query – Creates a new table from query results
Using Query Design View
- Open your database program (such as Microsoft Access or LibreOffice Base).
- Click the Create tab on the ribbon.
- Click Query Design to open the design view.
- A dialog box showing available tables will appear. Select the table or tables you want to use and click Add, then close the dialog box.
- The table(s) will appear in the query design window with a list of fields. Double-click each field you want to include in your query to add it to the design grid at the bottom.
- In the Criteria row under each field, type the condition you want to apply. For example, under a "Score" field, type
>80to find scores greater than 80. - Click the Run button (often shown as an exclamation mark) to see the results.
- Save your query by giving it a meaningful name, then click Save.
Using Query Wizard
- Click Query Wizard from the Create tab.
- Select Simple Query Wizard and click OK.
- Choose the table you want to query from the dropdown list.
- Select the fields you want to include by moving them to the Selected Fields box.
- Click Next, give your query a name, and click Finish to view the results.
A small shop owner in Arusha keeps a database of products called "Stock". The table below shows part of the data:
| ProductID | ProductName | Category | Quantity | UnitPrice (TZS) |
|---|---|---|---|---|
| P001 | Sugar 1kg | Food | 50 | 2,500 |
| P002 | Soap | Household | 30 | 1,200 |
| P003 | Rice 5kg | Food | 20 | 18,000 |
| P004 | Cooking Oil | Food | 15 | 8,500 |
| P005 | Candles | Household | 100 | 500 |
The shop owner wants to find all food items that cost less than TZS 10,000.
Creating the query:
- Open the database and select Query Design.
- Add the Stock table to the design window.
- Add these fields to the design grid:
ProductName,Category, andUnitPrice. - In the Criteria row under Category, type:
Food - In the Criteria row under UnitPrice, type:
<10000 - Click Run.
Result:
| ProductName | Category | UnitPrice (TZS) |
|---|---|---|
| Sugar 1kg | Food | 2,500 |
| Cooking Oil | Food | 8,500 |
The query shows only the food items that cost less than TZS 10,000, helping the shop owner quickly see which affordable food products are in stock.
You can combine criteria using AND and OR:
- AND – Both conditions must be true (example: Category is "Food" AND Price < 10000)
- OR – At least one condition must be true (example: Category is "Food" OR Category is "Household")
A school administrator in Tanzania can use queries to manage student records efficiently. For example, a headteacher at a secondary school in Dodoma can create a query to find all students in Form 3 who have unpaid school fees exceeding TZS 200,000, allowing the school to send timely payment reminders to parents and track fee collection accurately throughout the term.
Jinsi utakavyotathminiwaTathmini ya mchakato
Tathmini ya mchakato
Ability to create queries correctly
Swali
What is the main purpose of a query in a database?
Ingia ili kuwasilisha jibu lako na lihesabiwe katika umahiri wako.
Ingia ili kufanya mazoeziMwalimu
Umekwama? Niulize chochote kuhusu mada hii.
Ingia ili kumuuliza Mwalimu wa AI wa Sonza kuhusu swali hili.
Ingia ili kuulizaMajadiliano
Hakuna maswali bado