Group:  Microsoft Access ยป microsoft.public.access
Thread: Selecting first row of a table

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Selecting first row of a table
DV 20.09.2006 15:11:02
How can I query a table to select the first record of a group. For instance
if I have duplicate values for a client name, but the other fields for that
record contain differnt values, how can I select just the first record with
the corresponding values. Here's an example:

Client Name Date Value
ABC Co. 1/1/2006 1
ABC Co. 1/7/2006 7
ABC Co. 3/3/2006 10

How do I write a query to select only the first record for each change in
client name?
Re: Selecting first row of a table
"mcescher" <chris.meinders[ at ]gmail.com> 20.09.2006 16:04:47

DV wrote:
[Quoted Text]
> How can I query a table to select the first record of a group. For instance
> if I have duplicate values for a client name, but the other fields for that
> record contain differnt values, how can I select just the first record with
> the corresponding values. Here's an example:
>
> Client Name RecordDate RecordValue
> ABC Co. 1/1/2006 1
> ABC Co. 1/7/2006 7
> ABC Co. 3/3/2006 10
>
> How do I write a query to select only the first record for each change in
> client name?

First according to what criteria? Based on the earliest Date?

Also, Date and Value are reserved words, so they will give you problems
somewhere in your development process. I'll substitute RecordDate,
RecordValue

One way would be to use a group by clause in your SQL

SELECT [Client Name], Min([RecordDate]), Min([RecordValue])
FROM tblYourData
GROUP BY [Client Name]

HTH,
Chris M.

Re: Selecting first row of a table
"Larry Daugherty" <Larry.NoSpam.Daugherty[ at ]verizon.net> 20.09.2006 18:20:07
Look in Access help for "TOP"

HTH
--
-Larry-
--

"DV" <DV[ at ]discussions.microsoft.com> wrote in message
news:B4DE39FA-B1E7-429A-AA67-22FB2E9ADC75[ at ]microsoft.com...
[Quoted Text]
> How can I query a table to select the first record of a group. For
instance
> if I have duplicate values for a client name, but the other fields
for that
> record contain differnt values, how can I select just the first
record with
> the corresponding values. Here's an example:
>
> Client Name Date Value
> ABC Co. 1/1/2006 1
> ABC Co. 1/7/2006 7
> ABC Co. 3/3/2006 10
>
> How do I write a query to select only the first record for each
change in
> client name?


Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net