A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Combining Duplicates in Select qry



 
 
Thread Tools Display Modes
  #1  
Old April 26th, 2010, 10:49 AM posted to microsoft.public.access.queries
Jack Leach
external usenet poster
 
Posts: 33
Default Combining Duplicates in Select qry

Hi all, tia...

As of now I do this via DAO Recordsets, but I assume there must be a way to
handle it via query (also assuming that a query will always be faster than
working via Recordset). If I had a list of ten records consisting of a
PartNumber and Qty, and say three of those records are the same PartNumber
with various Qtys, how can I write a query that will return only one instance
of the PartNumber with a total Qty from all three records?

Ex.

PN | Qty
12345 | 2
12345 | 2
12345 | 2
12346 | 3
12347 | 10
12348 | 10

return:

12345 | 6
12346 | 3
12347 | 10
12348 | 10

Thanks for any insight,

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)

  #2  
Old April 26th, 2010, 11:36 AM posted to microsoft.public.access.queries
Stefan Hoffmann
external usenet poster
 
Posts: 991
Default Combining Duplicates in Select qry

hi Jack,

On 26.04.2010 11:49, Jack Leach wrote:
Ex.

PN | Qty
12345 | 2
12345 | 2
12345 | 2
12346 | 3
12347 | 10
12348 | 10

return:

12345 | 6
12346 | 3
12347 | 10
12348 | 10


SELECT [PN], Sum([Qty])
FROM yourTable
GROUP BY [PN]


mfG
-- stefan --
  #3  
Old April 26th, 2010, 11:39 AM posted to microsoft.public.access.queries
Kc-Mass
external usenet poster
 
Posts: 362
Default Combining Duplicates in Select qry

In the query design panel menu select "View", "Totals"
Then in the fields set PartNumber to "Group on" and set Qty to "Sum"

Regards

Kevin


"Jack Leach" dymondjack at hot mail dot com wrote in message
news
Hi all, tia...

As of now I do this via DAO Recordsets, but I assume there must be a way
to
handle it via query (also assuming that a query will always be faster than
working via Recordset). If I had a list of ten records consisting of a
PartNumber and Qty, and say three of those records are the same PartNumber
with various Qtys, how can I write a query that will return only one
instance
of the PartNumber with a total Qty from all three records?

Ex.

PN | Qty
12345 | 2
12345 | 2
12345 | 2
12346 | 3
12347 | 10
12348 | 10

return:

12345 | 6
12346 | 3
12347 | 10
12348 | 10

Thanks for any insight,

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



  #4  
Old April 26th, 2010, 12:43 PM posted to microsoft.public.access.queries
Jack Leach
external usenet poster
 
Posts: 33
Default Combining Duplicates in Select qry

Easy enough. Thanks guys.

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



"Jack Leach" wrote:

Hi all, tia...

As of now I do this via DAO Recordsets, but I assume there must be a way to
handle it via query (also assuming that a query will always be faster than
working via Recordset). If I had a list of ten records consisting of a
PartNumber and Qty, and say three of those records are the same PartNumber
with various Qtys, how can I write a query that will return only one instance
of the PartNumber with a total Qty from all three records?

Ex.

PN | Qty
12345 | 2
12345 | 2
12345 | 2
12346 | 3
12347 | 10
12348 | 10

return:

12345 | 6
12346 | 3
12347 | 10
12348 | 10

Thanks for any insight,

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:36 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.