MS Access Group By In A Query

I need some help better understanding the Group by in a query in MS Access. I want to group my field SKUs.SkuID but I don't need anything else in the totals for the other fields.

I have 4 fields and this includes two tables. Two fields in each table each field showing whether a record is new or modified. So in the criteria for each field I have = True

This is causing access to generate multiples of the same record. In SKUs there is 1 record and in Products there may be up to 5 records that match when the link is on SkuID. So the query results will show 5 lines of records and I just need one.

So what do I do to just group by in the SkuID field? I can't leave the other fields Total empty....

SELECT SKUs.SkuID
FROM Products RIGHT JOIN SKUs ON Products.SkuID = SKUs.SkuID
WHERE (((SKUs.SkuNew)=True)) OR (((SKUs.SkuModified)=True)) OR (((Products.NewItemFlag)=True))
ORDER BY SKUs.SkuID;

Open in new window

LVL 1
Dustin StanleyEntrepreneurAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NerdsOfTechTechnology ScientistCommented:
This is an xy question. What is your expected output? The RIGHT JOIN means get ALL records from the right table and join records from the left table (nulls for records that have a non-matching left table)

You would probably use DISTINCT in this case.

The SELECT DISTINCT statement is used to return only distinct (different) values. It works somewhat like GROUP BY without the expectations of aggregate functions being used.

try:

 SELECT DISTINCT SKUs.SkuID
 FROM Products RIGHT JOIN SKUs ON Products.SkuID = SKUs.SkuID
 WHERE (((SKUs.SkuNew)=True)) OR (((SKUs.SkuModified)=True)) OR (((Products.NewItemFlag)=True))
 ORDER BY SKUs.SkuID);

Open in new window


If this isn't what you are after, please provide example inputs and expected output.
0
Dustin StanleyEntrepreneurAuthor Commented:
I hope this helps make more since. Thanks for the help.Untitled.png
0
Dustin StanleyEntrepreneurAuthor Commented:
I believe I may have figured it out. Do I just use the WHERE in total for all the criteria of true like:
SELECT SKUs.SkuID
FROM Products RIGHT JOIN SKUs ON Products.SkuID = SKUs.SkuID
WHERE (((SKUs.SkuNew)=True)) OR (((SKUs.SkuModified)=True)) OR (((Products.NewItemFlag)=True)) OR (((Products.ModifiedItemFlag)=True))
GROUP BY SKUs.SkuID

Open in new window

0
NerdsOfTechTechnology ScientistCommented:
GROUP BY also works. I am not sure what you meant by totals.

SELECT SKUs.SkuID, SKUs.SkuNM 
 FROM Products RIGHT JOIN SKUs ON Products.SkuID = SKUs.SkuID
 WHERE (((SKUs.SkuNew)=True)) OR (((SKUs.SkuModified)=True)) OR (((Products.NewItemFlag)=True)) OR (((Products.ModifiedItemFlag)=True))
 GROUP BY SKUs.SkuID

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.