If you've got a table full of customer data but only need a few fields, a filtered list, or records in a particular order, you need a query. Queries are one of the most useful parts of Microsoft Access, and despite the fancy name, they are not magic. Well, maybe a little magic. But the good kind.
A table is where your data actually lives. Your CustomerT table might contain names, addresses, phone numbers, email addresses, credit limits, and plenty of other information. A query lets you ask Access for a specific view of that data, such as a customer phone list, customers in Florida, or everyone with a credit limit over $1,000. You are not making another copy of the customer table. You are saving instructions that tell Access what information to show.
A normal select query is live. When you open it, Access reads the current records from the table and displays the results that match your instructions. If someone adds a new customer to the table tomorrow, that customer can appear in the query tomorrow. If someone edits a customer's name, the query shows the edited name. The query is not a snapshot unless you intentionally create one using other tools.
The easiest way to make your first query is with the Simple Query Wizard. Go to the Create tab and click Query Wizard. Access offers several types of wizards, including Crosstab, Find Duplicates, and Find Unmatched. For a basic list of records and fields, choose Simple Query Wizard.
The wizard first asks which table or existing query should provide the data. Select the table you want, such as CustomerT. You will then see all of the fields available in that table.
Move only the fields you want into the selected-fields list. For example, you might choose CustomerID, FirstName, LastName, and State. You can use the arrow buttons, or simply double-click a field to add it. There is also a button that moves every field over at once, but that kind of defeats the purpose if you only need a small, useful list.
Including the primary key field, such as CustomerID, is generally a good idea. It uniquely identifies each record, so if you have two customers named John Smith, you still know exactly which John Smith you are looking at. The universe has supplied us with enough duplicate names already. No need to make it worse.
After selecting your fields, click Next. Some versions of Access may ask whether you want a Detail or Summary query. For a standard customer list, choose Detail. A detail query shows the individual records. Summary queries are for totals, averages, counts, and similar calculations.
Next, give the query a meaningful name. I would call this one CustomerQ. My usual naming convention is to end tables with T, queries with Q, forms with F, and reports with R. You do not have to use that convention, of course, but use something consistent. Also, I generally avoid spaces in object names. It saves headaches later, especially when you start working with expressions, SQL, macros, or VBA.
Choose Open the query to view information and click Finish. Access saves the query and opens the results in Datasheet View. You now have a query that shows just the four selected fields, without changing the underlying table.
One important warning: although deleting the saved query object does not delete your customer records, editing or deleting records through an updatable query can affect the actual table. A query result is often a live view of the data. If you delete Captain Picard from an editable query, he is gone from the table too. Engage carefully.
The Query Wizard is perfectly fine, especially if you are new to Access or your instructor specifically says to use it. But once you understand the basics, you will probably find that Query Design is faster and gives you much more control.
To create the same query manually, go to Create and click Query Design. Add the table you want, such as CustomerT, to the design area. Then double-click the fields you want in the grid below: CustomerID, FirstName, LastName, and State. Save the query as CustomerQ, then click the red exclamation point, called the Run button, to see the results.
That is all the Simple Query Wizard did behind the scenes. It created a select query and added your chosen fields. Query Design just lets you see and control the parts directly.
The real advantage of Query Design becomes obvious when you want to filter records. Suppose you only want customers in Florida. In the Criteria row beneath the State field, enter FL. When you run the query, Access displays only records where the State field contains FL. The other customer records are still safely sitting in the CustomerT table. The query is simply choosing not to show them.
You can use the same idea for numbers. Suppose you want customers whose credit limit is at least $1,000. Add the CreditLimit field to the design grid and enter >=1000 in the Criteria row. Do not use quotation marks around a number, and do not type a dollar sign or comma. This is a numeric comparison, not text.
If you use >1000, Access returns only customers whose credit limit is greater than $1,000. Customers at exactly $1,000 are excluded. If you use >=1000, customers with exactly $1,000 are included. Yes, those symbols from math class are back. They were waiting for you.
Sorting is just as easy. In the Sort row under LastName, choose Ascending to sort alphabetically from A to Z. Choose Descending to reverse it. You can also sort CreditLimit descending to put the customers with the highest limits at the top of the list.
Once you get comfortable with this, you can save separate queries for separate jobs. You might keep CustomerQ for a general list, FloridaCustomersQ for Florida customers, and HighCreditCustomersQ for people with larger credit limits. All of those queries can use the same CustomerT table. There is no need to make duplicate tables just to see your data in different ways.
The Simple Query Wizard is a good place to begin because it walks you through choosing a data source, selecting fields, naming the query, and opening the results. But Query Design is where you will spend most of your time once you start building practical Access databases. It makes filtering, sorting, adding fields, and changing your query much easier.
Watch the embedded video for a full walkthrough of creating the query with both the Query Wizard and Query Design, along with examples of criteria and sorting. Once you build a few simple queries, you will wonder how you ever worked with a giant table full of columns you did not need.
Live long and prosper,
RR



