Creating query to show only one of each category

AccessNData

New member
Local time
Today, 09:11
Joined
Nov 23, 2014
Messages
3
I am just starting out in access. This seems like a really dumb question, but I have a table that has different vehicle models. There is a "category" field that has vehicles under boats, cars, planes, heli, etc... How do I make a query that will only show the different categories that are used? So I would just want the category field showing one of each category that exists and not multiple records with the same category.
 
Hello and welcome to the forum!

Why does this seem like a dumb question? Is this for school? ;)
 
Use 'group by' on the Category field?
 
Why does this seem like a dumb question? Is this for school? ;)
Because it seems like such a simple thing to do, but when I do it, all the categories come up multiple times.

Use 'group by' on the Category field?
I couldn't get that to show just one of each category so I can tell how many unique categories there are.
 
try

Code:
SELECT DISTINCT Category
FROM myTable

Use 'group by' on the Category field?

I couldn't get that to show just one of each category so I can tell how many unique categories there are.

Probably because you are bringing more fields through than just category

Code:
SELECT Category
FROM myTable
GROUP BY Category

will do the same as the first code but is potentially less efficient - GROUP BY should be used when you also have fields which you want to sum, count, avg etc
 
SELECT DISTINCT Category
FROM tablename

You can only include the Category field or it will show the variation in the other fields too.

The Group By should do the same.
 
Thank you for all your help. I got it to work using the category by in the end. Not really sure how to use VBA for queries. Have only used it for controls, but I'm slowly learning. Thanks again.
 
Not really sure how to use VBA for queries.

None of what was posted was VBA. The code shown is the SQL view of the query. Right click on the query in design view and select SQL View.
 

Users who are viewing this thread

Back
Top Bottom