Nothing happened?
Does that mean the query ran and returned no records? or that the screen
still showed the query text? or that you got an error message?
Reformatting your query and stripping out the extra parentheses, I end up
with the following. And it looks as if it should work.
SELECT [Sort by Month].[Last Name],
[Sort by Month].[First Name],
[Sort by Month].[IRB#],
[Sort by Month].[Study #],
[Sort by Month].[Seq#],
[Sort by Month].Months,
[Sort by Month].[On-Study Date],
[Sort by Month].Schedule,
[Sort by Month].[F/U Status],
[Sort by Month].FollowUp
FROM [Sort by Month]
WHERE [Sort by Month].FollowUp In
(SELECT Min(TMP.FollowUp)
FROM [Sort by Month] as TMP
WHERE TMP.[Last Name] = [Sort by Month].[Last Name])
I am suspicious of just using Last Name to match on, but you know your data,
so I would guess this would work. I also assume that [Sort by Month] has
data in it. Is Sort By Month a table or a query?
Ted said:
purdear john,
your approach seemed to encapsulate the essence of this thing so i thought
i
would give it a whirl, and using the 'full' naming convention along with
the
total complement of fields in this (albeit for-testing-purposes-only)
version
of database, i cobbled the equivalent code you contributed into the SQL
query
viewer
SELECT [Sort by Month].[Last Name], [Sort by Month].[First Name], [Sort by
Month].[IRB#], [Sort by Month].[Study #], [Sort by Month].[Seq#], [Sort by
Month].Months, [Sort by Month].[On-Study Date], [Sort by Month].Schedule,
[Sort by Month].[F/U Status], [Sort by Month].FollowUp
FROM [Sort by Month]
WHERE ((([Sort by Month].FollowUp) In (SELECT Min(FollowUp)
FROM [Sort by Month] as TMP
WHERE TMP.[Last Name] = [Sort by Month].[Last Name])));
since i'm a relative access newbie perhaps there's something i'm failing
to
understand, but nothing happened when i clicked the "!" mark?
with best regards,
-ted
John Spencer said:
Assuming that the field FollowUp is the one that determines which record
to
return out of the group.
SELECT Last_Name, Months, On_Study_Date, Followup
FROM TheTable
WHERE TheTable.Followup IN
(SELECT Min(Followup)
FROM TheTable as TMP
WHERE TMP.LastName = TheTable.Last_Name)
i'll just add the contents of my (test) source table below and show you
which
rows the query would output:
here's the 'data' (actually, the working data would incorporate many
more
columns would be included in the final output, but the same rows as
shown
below would be output).
"Last_Name" "Months" " On_Study_Date" "FollowUp"
"Alkazar" 15 8/20/2004 11/21/2005 <--- output this one
"Alkazar" 18 8/20/2004 2/20/2006
"Alkazar" 21 8/20/2004 5/19/2006
"Alkazar" 24 8/20/2004 8/21/2006
"Alkazar" 30 8/20/2004 2/20/2007
"Alkazar" 36 8/20/2004 8/20/2007
"Alkazar" 42 8/20/2004 2/20/2008
"Alkazar" 48 8/20/2004 8/20/2008
"Alkazar" 54 8/20/2004 2/20/2009
"Alkazar" 60 8/20/2004 8/20/2009
"Alkazar" 72 8/20/2004 8/20/2010
"Alkazar" 84 8/20/2004 8/19/2011
"Alkazar" 96 8/20/2004 8/20/2012
"Alkazar" 108 8/20/2004 8/20/2013
"Alkazar" 120 8/20/2004 8/20/2014
"Mordred" 21 4/29/2004 1/30/2006 < ---- and output this one
"Mordred" 24 4/29/2004 4/28/2006
"Mordred" 30 4/29/2004 10/30/2006
"Mordred" 36 4/29/2004 4/30/2007
"Mordred" 42 4/29/2004 10/29/2007
"Mordred" 48 4/29/2004 4/29/2008
"Mordred" 54 4/29/2004 10/29/2008
"Mordred" 60 4/29/2004 4/29/2009
"Mordred" 72 4/29/2004 4/29/2010
"Mordred" 84 4/29/2004 4/29/2011
"Mordred" 96 4/29/2004 4/30/2012
"Mordred" 108 4/29/2004 4/29/2013
"Mordred" 120 4/29/2004 4/29/2014
"Valdez" 21 5/3/2004 2/3/2006 <---- and output this one
"Valdez" 24 5/3/2004 5/3/2006
"Valdez" 30 5/3/2004 11/3/2006
"Valdez" 36 5/3/2004 5/3/2007
"Valdez" 42 5/3/2004 11/2/2007
"Valdez" 48 5/3/2004 5/2/2008
"Valdez" 54 5/3/2004 11/3/2008
"Valdez" 60 5/3/2004 5/4/2009
"Valdez" 72 5/3/2004 5/3/2010
"Valdez" 84 5/3/2004 5/3/2011
"Valdez" 96 5/3/2004 5/3/2012
"Valdez" 108 5/3/2004 5/3/2013
"Valdez" 120 5/3/2004 5/2/2014
"Zanzibar" 21 5/3/2004 2/3/2006 <-- and output this one
"Zanzibar" 24 5/3/2004 5/3/2006
"Zanzibar" 30 5/3/2004 11/3/2006
"Zanzibar" 36 5/3/2004 5/3/2007
"Zanzibar" 42 5/3/2004 11/2/2007
"Zanzibar" 48 5/3/2004 5/2/2008
"Zanzibar" 54 5/3/2004 11/3/2008
"Zanzibar" 60 5/3/2004 5/4/2009
"Zanzibar" 72 5/3/2004 5/3/2010
"Zanzibar" 84 5/3/2004 5/3/2011
"Zanzibar" 96 5/3/2004 5/3/2012
"Zanzibar" 108 5/3/2004 5/3/2013
"Zanzibar" 120 5/3/2004 5/2/2014
:
(my computer hiccupped when i tried to send this a few minutes ago so
this
may be a repeat)...
i have a table (actually it's a query) i'm using as a source for this
current query.
the source file contains more than two columns, but the only two i
think
we
need focus on are "LastName" and "FollowUp" (a date field).
the records in the source can have repeats of "LastName" and what i
want
to
do is output a table/query result that captures the earliest value of
the
"FollowUp" date column for each unique person (i.e. "LastName").
i thought i understood groupby and the like, but this just isn't
working
today.
thoughts?