Access SQL query issue

I am trying to write a simple query to show me my "groups" of PC's I have in an Access database. I have a table called PC_EQUIP with 4 fields that I need: type, model, warranty and serial. This query works fine:

SELECT DISTINCT Type, Model, Warranty FROM PC_EQUIP

This shows me the information I mostly need since we order PC's in groups so the type, model and warranty date of each group will be the same and this query shows me the different groups that I want to see.

I really want to add two more pieces of information. Even though I am using DISTINCT, I would like to see one of the serial numbers for each DISTINCT group, dont care which. Obviously, if I add serial to the query above, I get a list of all records and the "DISTINCT" is useless. I would also like to add a COUNT to the query so it will show me how many rows are rolled up in that DISTINCT clause effectively showing me how many PC's I have on hand for that group,

The serial number part is optional but I cant seem to figure out how to make it return the count for each grouping.

Thanks
Mark LewisAsked:
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.

Jan LouwerensSoftware EngineerCommented:
SELECT DISTINCT Type, Model, Warranty, COUNT(*) OVER (PARTITION BY Type, Model, Warranty) AS Total, FIRST_VALUE(Serial) OVER (PARTITION BY Type, Model, Warranty) AS Serial FROM PC_EQUIP

Open in new window

0
Jan LouwerensSoftware EngineerCommented:
Without analytic functions, you can use this to get the count:

SELECT Type, Model, Warranty, COUNT(*) AS Total FROM PC_EQUIP
GROUP BY Type, Model, Warranty

Open in new window

0
PatHartmanCommented:
Jan, That is T-SQL syntax but the tables are Jet/ACE.

Mark, This should do it:

SELECT  Type, Model, Warranty, Max(SerialNumber) as MaxSerial, Count(*) as PCCount
FROM PC_EQUIP
Group By Type, Model, Warranty;
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
Jan LouwerensSoftware EngineerCommented:
Ah, using MIN or MAX on the Serial. So simple. Why didn't I think of that?!
0
Mark LewisAuthor Commented:
Just had to change the variable to Serial and it worked perfectly, Thanks. Jan's solution for a query without the inclusion of the serial number also worked great. Thanks again guys
0
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
SQL

From novice to tech pro — start learning today.