dbTalk Databases Forums  

Getting the First Record For A Particular Field

comp.databases.ms-access comp.databases.ms-access


Discuss Getting the First Record For A Particular Field in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Sheldon
 
Posts: n/a

Default Getting the First Record For A Particular Field - 07-30-2009 , 01:30 PM






To bring my question down to the simplest case - I have a table with
two records and two fields. The field names are FirstName and City.
If record 1 is Joe and Los Angeles and record 2 is Joe and San
Francisco, in my query, (no VBA), I would like to pull the first
record for each unique FirstName. I don't really care if I pick the
"Joe and Los Angeles" record or the "Joe and San Francisco" record but
I only want one unique occurrence of Joe with a city. Of course there
is a real business use for what I really need to do...

Thanks, Sheldon

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: Getting the First Record For A Particular Field - 07-30-2009 , 01:39 PM






Sheldon wrote:
Quote:
To bring my question down to the simplest case - I have a table with
two records and two fields. The field names are FirstName and City.
If record 1 is Joe and Los Angeles and record 2 is Joe and San
Francisco, in my query, (no VBA), I would like to pull the first
record for each unique FirstName. I don't really care if I pick the
"Joe and Los Angeles" record or the "Joe and San Francisco" record but
I only want one unique occurrence of Joe with a city. Of course there
is a real business use for what I really need to do...

Thanks, Sheldon
Use a groupsby/totals query.

Reply With Quote
  #3  
Old   
Bob Quintal
 
Posts: n/a

Default Re: Getting the First Record For A Particular Field - 07-30-2009 , 01:42 PM



Salad <oil (AT) vinegar (DOT) com> wrote in
news:75mdnTR8RoZadezXnZ2dnUVZ_vZi4p2d (AT) earthlink (DOT) com:

Quote:
Sheldon wrote:
To bring my question down to the simplest case - I have a table
with two records and two fields. The field names are FirstName
and City. If record 1 is Joe and Los Angeles and record 2 is Joe
and San Francisco, in my query, (no VBA), I would like to pull
the first record for each unique FirstName. I don't really care
if I pick the "Joe and Los Angeles" record or the "Joe and San
Francisco" record but I only want one unique occurrence of Joe
with a city. Of course there is a real business use for what I
really need to do...

Thanks, Sheldon

Use a groupsby/totals query.

How do you total cities?


--
Bob Quintal

PA is y I've altered my email address.

Reply With Quote
  #4  
Old   
Sheldon Potolsky
 
Posts: n/a

Default Re: Getting the First Record For A Particular Field - 07-30-2009 , 01:51 PM



On Jul 30, 2:39*pm, Salad <o... (AT) vinegar (DOT) com> wrote:
Quote:
Sheldon wrote:
To bring my question down to the simplest case - I have a table with
two records and two fields. *The field names are FirstName and City.
If record 1 is Joe and Los Angeles and record 2 is Joe and San
Francisco, in my query, (no VBA), I would like to pull the first
record for each unique FirstName. *I don't really care if I pick the
"Joe and Los Angeles" record or the "Joe and San Francisco" record but
I only want one unique occurrence of Joe with a city. *Of course there
is a real business use for what I really need to do...

Thanks, Sheldon

Use a groupsby/totals query.
I'm probably missing the obvious but GroupBy/Totals still shows me two
records. Can you be a little more specific on the query? Thanks.

Reply With Quote
  #5  
Old   
Krzysztof Naworyta
 
Posts: n/a

Default Re: Getting the First Record For A Particular Field - 07-30-2009 , 03:42 PM



Juzer Sheldon Potolsky <SHPsalm139 (AT) aol (DOT) com> napisał

Quote:
|| To bring my question down to the simplest case - I have a table with
|| two records and two fields. The field names are FirstName and City.
|| If record 1 is Joe and Los Angeles and record 2 is Joe and San
|| Francisco, in my query, (no VBA), I would like to pull the first
|| record for each unique FirstName.

| Use a groupsby/totals query.

I'm probably missing the obvious but GroupBy/Totals still shows me two
records. Can you be a little more specific on the query? Thanks.
Select
FirstName
, Min(City) as FirstCity
From ...
Group By
FirstName

--
KN

Reply With Quote
  #6  
Old   
Salad
 
Posts: n/a

Default Re: Getting the First Record For A Particular Field - 07-30-2009 , 07:59 PM



Sheldon Potolsky wrote:
Quote:
On Jul 30, 2:39 pm, Salad <o... (AT) vinegar (DOT) com> wrote:

Sheldon wrote:

To bring my question down to the simplest case - I have a table with
two records and two fields. The field names are FirstName and City.
If record 1 is Joe and Los Angeles and record 2 is Joe and San
Francisco, in my query, (no VBA), I would like to pull the first
record for each unique FirstName. I don't really care if I pick the
"Joe and Los Angeles" record or the "Joe and San Francisco" record but
I only want one unique occurrence of Joe with a city. Of course there
is a real business use for what I really need to do...

Thanks, Sheldon

Use a groupsby/totals query.


I'm probably missing the obvious but GroupBy/Totals still shows me two
records. Can you be a little more specific on the query? Thanks.
Uncheck city.

Reply With Quote
  #7  
Old   
Sheldon Potolsky
 
Posts: n/a

Default Re: Getting the First Record For A Particular Field - 07-31-2009 , 12:09 PM



Quote:
Use a groupsby/totals query.

I'm probably missing the obvious but GroupBy/Totals still shows me two
records. *Can you be a little more specific on the query? *Thanks.

Uncheck city.- Show quoted text -

- Show quoted text -
In my scenario, I'd want to see one entire record, so City would be
checked. But my actual scenario would be more like a table with two
records and four fields. The field names are FirstName, City, State
or Province, Country
So, if record 1 is Joe/Los Angeles/California/USA and
record 2 is Joe/Toronto/Ontario/Canada
I would like to pull one complete record for each unique FirstName.
i.e. In this case, I'd want to see
Joe/Los Angeles/California/USA or
Joe/Toronto/Ontario/Canada
I guess to get that, I'd need a MIN each for City, State or Province,
Country but my actual work problem uses at least one Expression so I
could not use MIN for that field. If my two records were in Table1,
maybe the best way to solve this would be to have an append query to
write just the FirstName field to Table2. So initially, Table2 would
have 1 record with "Joe" and the other three fields blank. Then I
would have an update query to populate the other three fields and
Access would choose either the Joe/Los Angeles/California/USA
combination or the one with Joe/Toronto/Ontario/Canada. I did test it
and it worked but wondering if this is the best/only solution. Thanks
for your ideas/input.

Sheldon

Reply With Quote
Reply




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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.