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  

DISTINCT or GROUP BY?



 
 
Thread Tools Display Modes
  #1  
Old March 10th, 2010, 10:51 PM posted to microsoft.public.access.queries
Kathy R.[_3_]
external usenet poster
 
Posts: 25
Default DISTINCT or GROUP BY?

Using Access 2007. My table is as follows

tblIndividual
IndID (autonumber, primary key)
OLD_FamID (not unique)
LastName (not unique)
OLD_MembID (unique)

I am trying to set up a query to show me the first instance of each
OLD_FamID.

Data:
OLD_FamID LastName OLD_MembID
1 Jones 1
1 Jones 2
1 Jones 3
2 Smith 4
2 Smith 5
3 Rogers 6
3 Rogers 7

Query would show
1 Jones 1
2 Smith 4
3 Rogers 6

How do I do this? I've been playing around a bit with both DISTINCT and
GROUP BY, but can't quite get it. Thanks for the help!
  #2  
Old March 11th, 2010, 12:15 AM posted to microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default DISTINCT or GROUP BY?

In query design view, depress the Totals button on the toolbar/ribbon so you
get the Totals row.

In the Totals row under OLD_FamID, choose Group By
In the Totals row under OLD_MembID choose Min

To get the name for that record see:
Getting a related field from a GroupBy (total) query
at:
http://www.mvps.org/access/queries/qry0020.htm

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"Kathy R." wrote in message
...
Using Access 2007. My table is as follows

tblIndividual
IndID (autonumber, primary key)
OLD_FamID (not unique)
LastName (not unique)
OLD_MembID (unique)

I am trying to set up a query to show me the first instance of each
OLD_FamID.

Data:
OLD_FamID LastName OLD_MembID
1 Jones 1
1 Jones 2
1 Jones 3
2 Smith 4
2 Smith 5
3 Rogers 6
3 Rogers 7

Query would show
1 Jones 1
2 Smith 4
3 Rogers 6

How do I do this? I've been playing around a bit with both DISTINCT and
GROUP BY, but can't quite get it. Thanks for the help!


  #3  
Old March 11th, 2010, 12:34 AM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default DISTINCT or GROUP BY?

Try this --
SELECT OLD_FamID, LastName, Min(OLD_MembID) AS OLD_MembID_x
FROM tblIndividual
BROUP BY OLD_FamID, LastName;

--
Build a little, test a little.


"Kathy R." wrote:

Using Access 2007. My table is as follows

tblIndividual
IndID (autonumber, primary key)
OLD_FamID (not unique)
LastName (not unique)
OLD_MembID (unique)

I am trying to set up a query to show me the first instance of each
OLD_FamID.

Data:
OLD_FamID LastName OLD_MembID
1 Jones 1
1 Jones 2
1 Jones 3
2 Smith 4
2 Smith 5
3 Rogers 6
3 Rogers 7

Query would show
1 Jones 1
2 Smith 4
3 Rogers 6

How do I do this? I've been playing around a bit with both DISTINCT and
GROUP BY, but can't quite get it. Thanks for the help!
.

  #4  
Old March 11th, 2010, 03:01 AM posted to microsoft.public.access.queries
Kathy R.[_3_]
external usenet poster
 
Posts: 25
Default DISTINCT or GROUP BY?

Thank you Allen, that worked great.



Allen Browne wrote:
In query design view, depress the Totals button on the toolbar/ribbon so
you get the Totals row.

In the Totals row under OLD_FamID, choose Group By
In the Totals row under OLD_MembID choose Min

To get the name for that record see:
Getting a related field from a GroupBy (total) query
at:
http://www.mvps.org/access/queries/qry0020.htm

  #5  
Old March 11th, 2010, 03:04 AM posted to microsoft.public.access.queries
Kathy R.[_3_]
external usenet poster
 
Posts: 25
Default DISTINCT or GROUP BY?

Thank you Karl,

I used Allen's solution. I had tried something similar to yours but it
didn't work because I had several cases where I had the same OLD_FamID
but different LastName(s). I neglected to mention that in my sample
data. I simplified it a bit too much.

I do appreciate the reply though. The more I learn the better!

Kathy R.

KARL DEWEY wrote:
Try this --
SELECT OLD_FamID, LastName, Min(OLD_MembID) AS OLD_MembID_x
FROM tblIndividual
BROUP BY OLD_FamID, LastName;

 




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 09:44 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.