A query is a saved question
Once data is in tables, almost everything useful is a query: which students failed, which books are overdue, how many sales each region made. A query stores the question and produces the answer afresh from the tables every time it runs, so it is always current.
In Access a query is built in the Query Design grid, and the same query can be viewed as SQL — the language the grid is really generating. Both appear in the exam.
Compare >60 AND 10A with >60 OR 10A on the same table. AND always returns fewer rows than either condition alone; OR always returns more. Swapping them is the commonest error in a query question.
Criteria
The criteria row of the design grid — the WHERE clause in SQL — decides which rows appear. Criteria on the same row of the grid are combined with AND; criteria on different rows are combined with OR.
Text values are enclosed in quotation marks and dates in hash symbols; numbers are written bare. Forgetting the quotation marks is the most frequent syntax error.
| Criterion | Selects |
|---|---|
| >60 | values greater than 60 |
| >=60 And <=80 | the range 60 to 80 inclusive |
| "10A" | exactly that text |
| Like "A*" | text beginning with A |
| Like "*khan*" | text containing khan anywhere |
| Between #1/1/2026# And #31/1/2026# | dates within January |
| Is Null | records where the field is empty |
| Not "10A" | everything except that value |
Empty is not the same as zero
A blank Marks field means the mark is unknown; a Marks field containing 0 means the student scored nothing. Is Null finds the first, =0 finds the second, and an average calculated over the column ignores the nulls but includes the zeros — producing two different answers. Treating a missing value as zero is the classic way to corrupt a report.
Queries across more than one table
Normalisation spread the data across several tables, so most real queries must bring it back together. A query listing student names alongside their class teacher needs both the STUDENT and CLASS tables, joined on the matching key.
Access joins them automatically if a relationship has been defined, which is one practical reason for setting the relationships up first. In SQL the join is written explicitly, matching the foreign key to the primary key it refers to.
STUDENT(RollNo, Name, ClassID) and CLASS(ClassID, ClassName, Teacher). Write a query listing each student's name with their teacher, for class 10A only, sorted by name.
- Both tables are needed, joined on
ClassID— the foreign key in STUDENT matching the primary key in CLASS.Without the join, every student would be paired with every class. SELECT Name, Teacher— only the two columns actually asked for.Selecting everything and letting the reader find the columns loses marks and is slower.FROM STUDENT INNER JOIN CLASS ON STUDENT.ClassID = CLASS.ClassIDThe join condition states which values must match.WHERE ClassName = "10A"Text in quotation marks. This is applied after the join, so it can use fields from either table.ORDER BY Name ASCAscending is the default, but stating it costs nothing and removes any doubt.
SELECT Name, Teacher FROM STUDENT INNER JOIN CLASS ON STUDENT.ClassID = CLASS.ClassID WHERE ClassName = "10A" ORDER BY Name
Calculations, totals and the other kinds of query
A query can produce columns that exist in no table. A calculated field is written as a name followed by a colon and an expression — Total: [Price] * [Quantity] — and is recomputed every time the query runs, which is why the result should never be stored in a table as well.
A totals query groups rows and summarises each group: count the students in each class, or average the marks per subject. The aggregate functions are Count, Sum, Avg, Min and Max.
Beyond selection there are action queries, which change the data rather than reading it: update, append, delete and make-table. These are irreversible in Access, so a backup before running one is not optional.
Never store a value you can calculate
If a table holds Price, Quantity and Total, the three can disagree the moment someone edits one of them — a classic redundancy. Calculate the total in a query or on the report instead, and it is always right by construction. The exception is a value that must be frozen in time, such as the price actually charged on an invoice, which must not change when the product price does.
Before you leave this chapter
- SELECT columns, FROM tables, WHERE rows, ORDER BY sequence.
- Same criteria row = AND (fewer rows); different rows = OR (more rows).
- Text in quotation marks, dates in hashes, numbers bare.
- Is Null finds empty fields, which are not the same as zero.
- Calculate values in a query rather than storing them — unless they must be frozen in time.
Action queries, and why they need care
A select query reads and changes nothing, so it can be run freely. An action query alters the data, and in Access the change is applied immediately with no undo.
There are four kinds. An update query changes values in existing records — raising every price by 5%. An append query copies records from one table into another. A delete query removes records matching its criteria. A make-table query creates a new table from the results of a select.
| Query type | Effect | Reversible? |
|---|---|---|
| Select | reads and displays | nothing changed |
| Update | changes field values | no |
| Append | adds records to another table | only by deleting them again |
| Delete | removes records | no |
| Make-table | creates a new table from results | delete the new table |
Run it as a select query first
Before running any delete or update query, change it to a select query with the same criteria and look at the rows it returns. Those are exactly the records that will be changed or destroyed. If the list is longer than expected — or contains something surprising — the criteria are wrong, and you have found out while it still costs nothing. Take a backup as well: Access action queries cannot be undone.