473,324 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Why is it that "Group by" eliminates duplicate records?

I'm fairly new to detailed data analysis. A lot of my queries end up using the Group By function, but other than knowing when to use it, I don't understand how it works. All I'm doing is hitting the sum key. All of my fields then show the Group By listed, so I can't figure out why it works the way I need it to. Can someone please explain this function to me? Just in case you need to know, I'm using Access 2000. I realize that knowing that it is working is a good thing, but it sure would be nice to know why. Thanks for some assistance.
Kelly
Nov 12 '07 #1
2 9759
MikeTheBike
639 Expert 512MB
I'm fairly new to detailed data analysis. A lot of my queries end up using the Group By function, but other than knowing when to use it, I don't understand how it works. All I'm doing is hitting the sum key. All of my fields then show the Group By listed, so I can't figure out why it works the way I need it to. Can someone please explain this function to me? Just in case you need to know, I'm using Access 2000. I realize that knowing that it is working is a good thing, but it sure would be nice to know why. Thanks for some assistance.
Kelly
Hi

Using GROUP BY on ALL fields is a waste of time. It does eliminate duplicate records, but this can be done with normal query and the DISTINCT operater (or DISTINCT ROW ?).

You should use GROUP BY when you want to use an aggregate function ie. Sum(), Ave() Count() etc. The fields used to group on will determine which records are aggregated (summed, averaged, counted etc.).

Does that shed any light ?

MTB
Nov 13 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
As Mike says ...

Essentially you only use group by on aggregate functions like sum(), count(), etc.

In the following query ...

Expand|Select|Wrap|Line Numbers
  1. SELECT MemberID, Sum(Fees)
  2. FROM tblMembers
  3. GROUP BY MemberID;
  4.  
You are basically saying that you would like to know the total fees paid by each member. By grouping the MemberID field you are simply saying get the sum (total) of the fees paid by each member.
Nov 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
1
by: Tamer Higazi | last post by:
Hi! I have problems creating joins between tables and to limit rows for a specified clolumn. I have 2 tables! employees departments I face the problems with the GROUP BY clause and i don't...
2
by: mark | last post by:
How can I use "Group By" or a formula to group my query results in 1-year periods from a given date, e.g. 3 groups: 1 Sept 2001 - 1 Sept 2002 1 Sept 2002 - 1 Sept 2003 1 Sept 2003 - 1 Sept 2004 ...
0
by: TaeHo Yoo | last post by:
After running my code, group tree(the left section of the report) changes but not the content in the report. My code is ---------------------------------------------------------- Private Sub...
5
by: Dave Smithz | last post by:
Hi there, Been working on an evolving DB program for a while now. Suddenly I have come across a situation where I need to update a table based on a group by query. For example, I have a table...
1
by: ASF | last post by:
Is it possible to create a crystal report graph in which a user selects some parameters---a date range for instance--- AND the table field that they wish to "Group By" then hits the submit button...
1
by: Thomas Qi | last post by:
There is a basic sql below: SELECT CTEnr AS ID, TimeStamp, DatagramSize, Source AS LocalIP, Destination AS RemoteIP, Protocol, Messages, SourcePort AS LocalPort, DestPort AS RemotePort FROM...
15
by: wizofaus | last post by:
I have a chunk of code which is essentially IDbCommand cmd = db.CreateCommand(); cmd.CommandText = "SELECT X, Y, Count(*) FROM Foo WHERE Z = 1 GROUP BY X, Y"; using (IDataReader reader =...
2
by: nico3334 | last post by:
Hi, I have a SQL table that has data like this: Title Month Info 1 ---- 7 ---- 100 1 ---- 7 ---- 100 1 ---- 8 ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.