Lesson 21 of 50 – Query Basics in MS Access
42%

Query Basics in MS Access

A query in Microsoft Access is used to retrieve, filter, sort, calculate, and analyze data from one or more tables. Queries help you find specific information without manually searching through every record.

1. What Is a Query?

A query is a database object that allows you to ask questions about your data and display the results that match your requirements.

Example: Students Table
StudentID StudentName Course Fees
101 Amit ADCA 10000
102 Priya Tally Prime 4000
103 Rahul ADCA 10000
104 Neha Web Development 12000

You can use a query to answer questions such as:

  • Which students are enrolled in ADCA?
  • Which students have fees greater than ₹5,000?
  • How many students are enrolled in each course?
  • What is the total fee amount for all students?
Remember: A Select query normally displays matching data without changing the records stored in the source tables.

2. Why Do We Use Queries?

  • Retrieve data: Display selected fields from a table.
  • Filter records: Show records that match specific conditions.
  • Sort data: Arrange records in ascending or descending order.
  • Calculate values: Perform calculations such as totals and averages.
  • Combine tables: Retrieve related information from multiple tables.
  • Update data: Modify multiple records using an Update query.
  • Delete data: Remove records using a Delete query.

Queries are useful in schools, libraries, offices, businesses, and student management systems.

3. Types of Queries in MS Access

1. Select Query

Retrieves and displays records that match specified conditions. It is one of the most commonly used query types.

Example: Display all students enrolled in ADCA.

2. Parameter Query

Prompts the user to enter a value when the query runs.

Example: Enter a course name to display students in that course.

3. Update Query

Changes existing values in multiple records that match specified conditions.

Example: Increase the fees for students in a particular course.

4. Delete Query

Deletes records that match specified conditions.

Example: Delete test records that are no longer required.

5. Append Query

Adds records from one data source to an existing table.

6. Make-Table Query

Creates a new table from the results of a query.

7. Crosstab Query

Summarizes data into row and column headings, making it useful for comparing totals across categories.

Warning: Update, Delete, Append, and Make-Table queries can change or create data. Review their settings carefully before running them.

4. How to Create a Query Using Query Wizard

  1. Open your Microsoft Access database.
  2. Click the Create tab on the ribbon.
  3. Click Query Wizard.
  4. Select Simple Query Wizard and click OK.
  5. Choose the table or query that contains your data.
  6. Select the fields you want to display.
  7. Click Next.
  8. Choose Detail or Summary if the wizard offers that choice.
  9. Enter a name for your query.
  10. Choose to open the query to view results and finish the wizard.
Example: Select StudentName and Course from the Students table to create a query that displays each student's name and course.

5. How to Create a Query in Design View

Query Design View gives you more control over the fields, sorting, and criteria used in a query.

  1. Open your database.
  2. Click the Create tab.
  3. Select Query Design.
  4. Add the table containing your data.
  5. Close the Show Table or Add Tables window.
  6. Double-click the fields you want to include in the query.
  7. Set any sorting options or criteria in the query grid.
  8. Click Run (!) to display the results.
  9. Save the query with a meaningful name.
Example: Query Design Grid
Field StudentName Course Fees
Table Students Students Students
Sort Ascending
Show ✓ ✓ ✓
Criteria "ADCA" >5000

This grid selects the StudentName, Course, and Fees fields. It sorts names alphabetically and applies criteria to the Course and Fees fields.

Because both criteria are on the same Criteria row, the query returns records where Course is ADCA and Fees is greater than 5000.

6. Understanding Query Criteria

Criteria are conditions that determine which records appear in a query's results.

Requirement Criteria
Fees equal to 10000 =10000
Fees greater than 5000 >5000
Fees less than 10000 <10000
Course equals ADCA "ADCA"
Course is not ADCA <>"ADCA"
Student name begins with A Like "A*"
Fees between 5000 and 10000 Between 5000 And 10000

In Access's default ANSI-89 query pattern syntax, an asterisk (*) matches zero or more characters. Database settings and ANSI-92 mode can affect wildcard syntax.

Tip: Text criteria are commonly enclosed in quotation marks. Date criteria in Access queries commonly use the # symbol, such as #10/13/2026#.

7. Introduction to SQL in MS Access

SQL stands for Structured Query Language. It is used to communicate with databases and retrieve or modify data.

In Microsoft Access, you can view or write SQL by opening a query and switching to SQL View.

Example 1: Display All Records
SELECT *
FROM Students;

The asterisk (*) selects all fields from the Students table.

Example 2: Display Selected Fields
SELECT StudentName, Course
FROM Students;

This query displays only the StudentName and Course fields.

Example 3: Filter Records
SELECT *
FROM Students
WHERE Course = "ADCA";

This query returns records whose Course value is ADCA.

Example 4: Sort Records
SELECT StudentName, Fees
FROM Students
ORDER BY Fees DESC;

This query sorts student records by Fees from highest to lowest.

Note: These examples assume your table is named Students and contains the specified field names. Use your actual table and field names when writing queries.

8. Saving and Running a Query

To Run a Query
  1. Open the query in Design View or SQL View.
  2. Click Run (!) on the ribbon, or use Datasheet View where appropriate.
  3. Review the results.
To Save a Query
  1. Press Ctrl + S or click Save.
  2. Enter a meaningful query name.
  3. Click OK.
  4. Find the saved query in the Navigation Pane.

Saved queries can be opened again and run whenever you need their results. A saved Select query stores the query definition, not a separate permanent copy of its displayed results.

9. Practical Assignment

Create a Students table containing these fields:

  • StudentID — AutoNumber
  • StudentName — Short Text
  • Course — Short Text
  • Fees — Currency
Tasks
  1. Enter at least ten student records.
  2. Create a query to display all student records.
  3. Create a query that displays only StudentName and Course.
  4. Filter students whose Course is ADCA.
  5. Find students whose Fees are greater than 5000.
  6. Sort students by StudentName in ascending order.
  7. Write a SQL query to display students with fees below 10000.
  8. Save your queries with meaningful names.

Goal: Learn to create, run, save, and understand basic queries in Microsoft Access.

10. Revision Questions

  1. What is a query in MS Access?
  2. Why do we use queries?
  3. What is a Select query?
  4. What is the purpose of Query Design View?
  5. What are query criteria?
  6. What does SELECT * mean in SQL?
  7. What is the purpose of the WHERE clause?
  8. How do you save a query?

🧠 Quick Quiz

1. What is the main purpose of a Select query?




2. Which SQL clause is commonly used to filter records?




3. What does SELECT * retrieve?